From 9419642525742c58acb3bd72c077f6015e3b467f Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Sat, 30 Jul 2022 23:17:57 +0200 Subject: [PATCH] Added cache to the number of cultures --- I18N Commander/Processor/AppSettings.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/I18N Commander/Processor/AppSettings.cs b/I18N Commander/Processor/AppSettings.cs index 555731d..b99d94d 100644 --- a/I18N Commander/Processor/AppSettings.cs +++ b/I18N Commander/Processor/AppSettings.cs @@ -212,9 +212,15 @@ public static class AppSettings #region Translation Settings #region Number of cultures + + private static int CACHE_NUMBER_OF_CULTURES = -1; public static async Task GetNumberCultures() { + // When possible, use the cache: + if (CACHE_NUMBER_OF_CULTURES > -1) + return CACHE_NUMBER_OF_CULTURES; + // Get the database: await using var db = ProcessorMeta.ServiceProvider.GetRequiredService(); @@ -223,8 +229,12 @@ public static class AppSettings // We have at least one default culture: if(count == 0) + { + CACHE_NUMBER_OF_CULTURES = 1; return 1; + } + CACHE_NUMBER_OF_CULTURES = count; return count; } @@ -291,6 +301,10 @@ public static class AppSettings await db.Settings.AddAsync(setting); await db.SaveChangesAsync(); + + // Update the number of cultures cache: + if(CACHE_NUMBER_OF_CULTURES > -1) + CACHE_NUMBER_OF_CULTURES++; } }