mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 17:08:47 +08:00
Cache CultureRecords by both Id and Name (#8708)
This commit is contained in:
parent
bdba35c704
commit
729f8ddd75
@ -62,12 +62,36 @@ namespace Orchard.Localization.Services {
|
||||
return _workContextAccessor.GetContext().CurrentCulture;
|
||||
}
|
||||
|
||||
protected Dictionary<int, CultureRecord> GetAllCulturesById() {
|
||||
return _cacheManager.Get("all_culture_records_by_id", true, context => {
|
||||
context.Monitor(_signals.When("culturesChanged"));
|
||||
|
||||
return _cultureRepository.Table
|
||||
.ToDictionary(cr => cr.Id);
|
||||
});
|
||||
}
|
||||
public CultureRecord GetCultureById(int id) {
|
||||
return _cultureRepository.Get(id);
|
||||
var cultures = GetAllCulturesById();
|
||||
CultureRecord result;
|
||||
cultures.TryGetValue(id, out result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected Dictionary<string, CultureRecord> GetAllCulturesByName() {
|
||||
return _cacheManager.Get("all_culture_records_by_name", true, context => {
|
||||
context.Monitor(_signals.When("culturesChanged"));
|
||||
|
||||
return _cultureRepository.Table
|
||||
.ToDictionary(cr => cr.Culture);
|
||||
});
|
||||
}
|
||||
public CultureRecord GetCultureByName(string cultureName) {
|
||||
return _cultureRepository.Get(cr => cr.Culture == cultureName);
|
||||
var cultures = GetAllCulturesByName();
|
||||
CultureRecord result;
|
||||
cultures.TryGetValue(cultureName, out result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public string GetSiteCulture() {
|
||||
|
Loading…
Reference in New Issue
Block a user