Added cache to the number of cultures
This commit is contained in:
parent
276fa51e92
commit
9419642525
@ -212,9 +212,15 @@ public static class AppSettings
|
|||||||
#region Translation Settings
|
#region Translation Settings
|
||||||
|
|
||||||
#region Number of cultures
|
#region Number of cultures
|
||||||
|
|
||||||
|
private static int CACHE_NUMBER_OF_CULTURES = -1;
|
||||||
|
|
||||||
public static async Task<int> GetNumberCultures()
|
public static async Task<int> GetNumberCultures()
|
||||||
{
|
{
|
||||||
|
// When possible, use the cache:
|
||||||
|
if (CACHE_NUMBER_OF_CULTURES > -1)
|
||||||
|
return CACHE_NUMBER_OF_CULTURES;
|
||||||
|
|
||||||
// Get the database:
|
// Get the database:
|
||||||
await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
|
await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
|
||||||
|
|
||||||
@ -223,8 +229,12 @@ public static class AppSettings
|
|||||||
|
|
||||||
// We have at least one default culture:
|
// We have at least one default culture:
|
||||||
if(count == 0)
|
if(count == 0)
|
||||||
|
{
|
||||||
|
CACHE_NUMBER_OF_CULTURES = 1;
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
CACHE_NUMBER_OF_CULTURES = count;
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,6 +301,10 @@ public static class AppSettings
|
|||||||
|
|
||||||
await db.Settings.AddAsync(setting);
|
await db.Settings.AddAsync(setting);
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
|
|
||||||
|
// Update the number of cultures cache:
|
||||||
|
if(CACHE_NUMBER_OF_CULTURES > -1)
|
||||||
|
CACHE_NUMBER_OF_CULTURES++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user