From 7f65b0018a87d64aeb965bbf284f265a1b45426f Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Wed, 8 May 2024 20:07:44 +0200 Subject: [PATCH] Remove CachingBookmarkStore class and its references (#5354) The class CachingBookmarkStore was removed from the project as it is no longer being used. The reference to this class in CachingWorkflowRuntimeFeature.cs was also eliminated as part of this change. --- .../Features/CachingWorkflowRuntimeFeature.cs | 4 +- .../Stores/CachingBookmarkStore.cs | 64 ------------------- 2 files changed, 1 insertion(+), 67 deletions(-) delete mode 100644 src/modules/Elsa.Workflows.Runtime/Stores/CachingBookmarkStore.cs diff --git a/src/modules/Elsa.Workflows.Runtime/Features/CachingWorkflowRuntimeFeature.cs b/src/modules/Elsa.Workflows.Runtime/Features/CachingWorkflowRuntimeFeature.cs index 859c010d7..fc521f9ed 100644 --- a/src/modules/Elsa.Workflows.Runtime/Features/CachingWorkflowRuntimeFeature.cs +++ b/src/modules/Elsa.Workflows.Runtime/Features/CachingWorkflowRuntimeFeature.cs @@ -23,8 +23,6 @@ public class CachingWorkflowRuntimeFeature : FeatureBase public override void Apply() { // Decorators. - Services - .Decorate() - .Decorate(); + Services.Decorate(); } } \ No newline at end of file diff --git a/src/modules/Elsa.Workflows.Runtime/Stores/CachingBookmarkStore.cs b/src/modules/Elsa.Workflows.Runtime/Stores/CachingBookmarkStore.cs deleted file mode 100644 index c28e2c609..000000000 --- a/src/modules/Elsa.Workflows.Runtime/Stores/CachingBookmarkStore.cs +++ /dev/null @@ -1,64 +0,0 @@ -using Elsa.Caching; -using Elsa.Workflows.Contracts; -using Elsa.Workflows.Runtime.Contracts; -using Elsa.Workflows.Runtime.Entities; -using Elsa.Workflows.Runtime.Filters; -using Microsoft.Extensions.Caching.Memory; - -namespace Elsa.Workflows.Runtime.Stores; - -/// -/// A decorator for that caches bookmark records. -/// -public class CachingBookmarkStore(IBookmarkStore decoratedStore, ICacheManager cacheManager, IHasher hasher) : IBookmarkStore -{ - private static readonly string CacheInvalidationTokenKey = typeof(CachingBookmarkStore).FullName!; - - /// - public async ValueTask SaveAsync(StoredBookmark record, CancellationToken cancellationToken = default) - { - await cacheManager.TriggerTokenAsync(CacheInvalidationTokenKey, cancellationToken); - await decoratedStore.SaveAsync(record, cancellationToken); - } - - /// - public async ValueTask SaveManyAsync(IEnumerable records, CancellationToken cancellationToken) - { - await cacheManager.TriggerTokenAsync(CacheInvalidationTokenKey, cancellationToken); - await decoratedStore.SaveManyAsync(records, cancellationToken); - } - - /// - public async ValueTask FindAsync(BookmarkFilter filter, CancellationToken cancellationToken = default) - { - var cacheKey = hasher.Hash(filter); - return (await GetOrCreateAsync(cacheKey, async () => await decoratedStore.FindAsync(filter, cancellationToken)))!; - } - - /// - public async ValueTask> FindManyAsync(BookmarkFilter filter, CancellationToken cancellationToken = default) - { - var cacheKey = hasher.Hash(filter); - return (await GetOrCreateAsync(cacheKey, async () => await decoratedStore.FindManyAsync(filter, cancellationToken)))!; - } - - /// - public async ValueTask DeleteAsync(BookmarkFilter filter, CancellationToken cancellationToken = default) - { - await cacheManager.TriggerTokenAsync(CacheInvalidationTokenKey, cancellationToken); - return await decoratedStore.DeleteAsync(filter, cancellationToken); - } - - private async ValueTask GetOrCreateAsync(string key, Func> factory) - { - var cacheEntry = await cacheManager.GetOrCreateAsync(key, async entry => - { - var invalidationRequestToken = cacheManager.GetToken(CacheInvalidationTokenKey); - entry.AddExpirationToken(invalidationRequestToken); - entry.SetAbsoluteExpiration(cacheManager.CachingOptions.Value.CacheDuration); - return await factory(); - }); - - return cacheEntry!; - } -} \ No newline at end of file