Cache CultureRecords by both Id and Name (#8708)

This commit is contained in:
Matteo Piovanelli 2023-07-07 09:58:17 +02:00 committed by GitHub
parent bdba35c704
commit 729f8ddd75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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() {