From 088af92fd052a05ff691c8b730a6649793274925 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 30 Dec 2020 23:41:39 +0100 Subject: [PATCH] Consistent cache keys --- .../HandleRules/EventEnricher.cs | 8 ++--- .../Scripting/Internal/Parser.cs | 29 +++++++------------ .../Scripting/JintScriptEngine.cs | 4 +-- .../Apps/Indexes/AppsIndex.cs | 21 +++++++------- .../Rules/RuleEnqueuer.cs | 4 ++- .../Schemas/Indexes/SchemasIndex.cs | 21 +++++++------- .../UsageTracking/CachingUsageTracker.cs | 4 +-- 7 files changed, 42 insertions(+), 49 deletions(-) diff --git a/backend/src/Squidex.Domain.Apps.Core.Operations/HandleRules/EventEnricher.cs b/backend/src/Squidex.Domain.Apps.Core.Operations/HandleRules/EventEnricher.cs index 221ac18f8..29688c57d 100644 --- a/backend/src/Squidex.Domain.Apps.Core.Operations/HandleRules/EventEnricher.cs +++ b/backend/src/Squidex.Domain.Apps.Core.Operations/HandleRules/EventEnricher.cs @@ -18,7 +18,7 @@ namespace Squidex.Domain.Apps.Core.HandleRules { public sealed class EventEnricher : IEventEnricher { - private static readonly TimeSpan UserCacheDuration = TimeSpan.FromMinutes(10); + private static readonly TimeSpan CacheDuration = TimeSpan.FromMinutes(10); private readonly IMemoryCache userCache; private readonly IUserResolver userResolver; @@ -56,11 +56,11 @@ namespace Squidex.Domain.Apps.Core.HandleRules private Task FindUserAsync(RefToken actor) { - var key = $"EventEnrichers_Users_{actor.Identifier}"; + var cacheKey = $"{typeof(EventEnricher)}_Users_{actor.Identifier}"; - return userCache.GetOrCreateAsync(key, async x => + return userCache.GetOrCreateAsync(cacheKey, async x => { - x.AbsoluteExpirationRelativeToNow = UserCacheDuration; + x.AbsoluteExpirationRelativeToNow = CacheDuration; IUser? user; try diff --git a/backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/Internal/Parser.cs b/backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/Internal/Parser.cs index b2d3087f5..0e01d4153 100644 --- a/backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/Internal/Parser.cs +++ b/backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/Internal/Parser.cs @@ -15,40 +15,33 @@ namespace Squidex.Domain.Apps.Core.Scripting.Internal { internal sealed class Parser { - private static readonly TimeSpan Expiration = TimeSpan.FromMinutes(10); + private static readonly TimeSpan CacheDuration = TimeSpan.FromMinutes(10); private static readonly ParserOptions DefaultParserOptions = new ParserOptions { AdaptRegexp = true, Tolerant = true, Loc = true }; - private readonly IMemoryCache memoryCache; + private readonly IMemoryCache cache; - public Parser(IMemoryCache memoryCache) + public Parser(IMemoryCache cache) { - Guard.NotNull(memoryCache, nameof(memoryCache)); + Guard.NotNull(cache, nameof(cache)); - this.memoryCache = memoryCache; + this.cache = cache; } public Script Parse(string script) { - var key = Key(script); + var cacheKey = $"{typeof(Parser)}_Script_{script}"; - if (!memoryCache.TryGetValue