From 6d5beaf073d0707aa2c4e246365322ca32af1eda Mon Sep 17 00:00:00 2001 From: jtkech Date: Tue, 31 Oct 2023 02:32:55 +0100 Subject: [PATCH] Invalidate cache on updating store --- .../Documents/DocumentManager.cs | 16 ++++++++++++++-- .../Documents/VolatileDocumentManager.cs | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/OrchardCore/OrchardCore.Infrastructure/Documents/DocumentManager.cs b/src/OrchardCore/OrchardCore.Infrastructure/Documents/DocumentManager.cs index d7922a84b09..58dba7b3948 100644 --- a/src/OrchardCore/OrchardCore.Infrastructure/Documents/DocumentManager.cs +++ b/src/OrchardCore/OrchardCore.Infrastructure/Documents/DocumentManager.cs @@ -186,7 +186,7 @@ public async Task UpdateAsync(TDocument document, Func afterUpd { await DocumentStore.UpdateAsync(document, async document => { - await SetInternalAsync(document); + await InvalidateInternalAsync(document); if (afterUpdateAsync != null) { @@ -204,7 +204,7 @@ await DocumentStore.UpdateAsync(document, async document => // But still update the shared cache after committing. DocumentStore.AfterCommitSuccess(async () => { - await SetInternalAsync(document); + await InvalidateInternalAsync(document); if (afterUpdateAsync != null) { @@ -352,6 +352,18 @@ protected async Task SetInternalAsync(TDocument document, bool failover = false) } } + protected async Task InvalidateInternalAsync(TDocument document, bool failover = false) + { + if (_isDistributed) + { + await _distributedCache.RemoveAsync(_options.CacheIdKey); + } + else + { + _memoryCache.Remove(_options.CacheIdKey); + } + } + private async Task GetFromDistributedCacheAsync() { byte[] data = null; diff --git a/src/OrchardCore/OrchardCore.Infrastructure/Documents/VolatileDocumentManager.cs b/src/OrchardCore/OrchardCore.Infrastructure/Documents/VolatileDocumentManager.cs index 09318ccc5c9..275c575bdf3 100644 --- a/src/OrchardCore/OrchardCore.Infrastructure/Documents/VolatileDocumentManager.cs +++ b/src/OrchardCore/OrchardCore.Infrastructure/Documents/VolatileDocumentManager.cs @@ -99,7 +99,7 @@ public async Task UpdateAtomicAsync(Func> updateAsync, Func