From 4c463287ca0aec7fd717073b3b0eddc23bfab873 Mon Sep 17 00:00:00 2001 From: Marek Dzikiewicz Date: Wed, 16 Apr 2025 08:28:43 -0400 Subject: [PATCH] #8828: Expose Redis API to clear multiple keys using wildcard syntax (#8829) * #8828: Expose Redis API to clear multiple keys using wildcard syntax * #8828: Rename IRedisCacheStorageProvider to ICacheStorageProviderWithKeyPrefix * Moving ICacheStorageProviderWithKeyPrefix to Orchard.Caching --------- Co-authored-by: Benedek Farkas --- .../Orchard.Caching/Services/ICacheStorageProvider.cs | 4 ++++ .../Orchard.Redis/Caching/RedisCacheStorageProvider.cs | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Caching/Services/ICacheStorageProvider.cs b/src/Orchard.Web/Modules/Orchard.Caching/Services/ICacheStorageProvider.cs index 4be4dc974..200f001fc 100644 --- a/src/Orchard.Web/Modules/Orchard.Caching/Services/ICacheStorageProvider.cs +++ b/src/Orchard.Web/Modules/Orchard.Caching/Services/ICacheStorageProvider.cs @@ -8,4 +8,8 @@ namespace Orchard.Caching.Services { void Remove(string key); void Clear(); } + + public interface ICacheStorageProviderWithKeyPrefix : ICacheStorageProvider { + void Clear(string key); + } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Redis/Caching/RedisCacheStorageProvider.cs b/src/Orchard.Web/Modules/Orchard.Redis/Caching/RedisCacheStorageProvider.cs index 5f3c8896d..50fd81649 100644 --- a/src/Orchard.Web/Modules/Orchard.Redis/Caching/RedisCacheStorageProvider.cs +++ b/src/Orchard.Web/Modules/Orchard.Redis/Caching/RedisCacheStorageProvider.cs @@ -9,10 +9,9 @@ using StackExchange.Redis; using System; namespace Orchard.Redis.Caching { - [OrchardFeature("Orchard.Redis.Caching")] [OrchardSuppressDependency("Orchard.Caching.Services.DefaultCacheStorageProvider")] - public class RedisCacheStorageProvider : Component, ICacheStorageProvider { + public class RedisCacheStorageProvider : Component, ICacheStorageProviderWithKeyPrefix { public const string ConnectionStringKey = "Orchard.Redis.Cache"; private readonly ShellSettings _shellSettings; @@ -61,6 +60,10 @@ namespace Orchard.Redis.Caching { _connectionMultiplexer.KeyDeleteWithPrefix(GetLocalizedKey("*")); } + public void Clear(string key) { + _connectionMultiplexer.KeyDeleteWithPrefix(GetLocalizedKey($"{_shellSettings.Name}:{key}")); + } + private string GetLocalizedKey(string key) { return _shellSettings.Name + ":Cache:" + key; }