diff --git a/source/SimpleRedirects.Core/Notifications/RedirectCacheRefresherNotification.cs b/source/SimpleRedirects.Core/Notifications/RedirectCacheRefresherNotification.cs
new file mode 100644
index 0000000..d1c4f05
--- /dev/null
+++ b/source/SimpleRedirects.Core/Notifications/RedirectCacheRefresherNotification.cs
@@ -0,0 +1,12 @@
+using Umbraco.Cms.Core.Notifications;
+using Umbraco.Cms.Core.Sync;
+
+namespace SimpleRedirects.Core.Notifications
+{
+ public class RedirectCacheRefresherNotification : CacheRefresherNotification
+ {
+ public RedirectCacheRefresherNotification(object messageObject, MessageType messageType) : base(messageObject, messageType)
+ {
+ }
+ }
+}
diff --git a/source/SimpleRedirects.Core/RedirectRepository.cs b/source/SimpleRedirects.Core/RedirectRepository.cs
index ad77382..6a618b8 100644
--- a/source/SimpleRedirects.Core/RedirectRepository.cs
+++ b/source/SimpleRedirects.Core/RedirectRepository.cs
@@ -7,6 +7,7 @@
using SimpleRedirects.Core.Extensions;
using SimpleRedirects.Core.Models;
using SimpleRedirects.Core.Utilities.Caching;
+using Umbraco.Cms.Core.Cache;
using Umbraco.Cms.Core.Scoping;
using Umbraco.Extensions;
@@ -15,14 +16,16 @@ namespace SimpleRedirects.Core
public class RedirectRepository
{
private readonly ICacheManager _cacheManager;
- private const string CacheCategoryKey = "Redirects";
+ private readonly DistributedCache _distributedCache;
+ public const string CacheCategoryKey = "Redirects";
private readonly IScopeProvider _scopeProvider;
- public RedirectRepository(IScopeProvider scopeProvider, ICacheManager cacheManager)
+ public RedirectRepository(IScopeProvider scopeProvider, ICacheManager cacheManager, DistributedCache distributedCache)
{
_scopeProvider = scopeProvider;
_cacheManager = cacheManager;
+ _distributedCache = distributedCache;
}
///
@@ -195,7 +198,7 @@ public Redirect FindRedirect(Uri oldUrl)
///
public void ClearCache()
{
- _cacheManager.ClearByKeyPrefix(CacheCategoryKey);
+ _distributedCache.RefreshAll(RedirectCacheRefresher.UniqueId);
}
///
diff --git a/source/SimpleRedirects.Core/SimpleRedirects.Core.csproj b/source/SimpleRedirects.Core/SimpleRedirects.Core.csproj
index 77ef68a..3ba4091 100644
--- a/source/SimpleRedirects.Core/SimpleRedirects.Core.csproj
+++ b/source/SimpleRedirects.Core/SimpleRedirects.Core.csproj
@@ -1,4 +1,4 @@
-
+
net5.0
.
diff --git a/source/SimpleRedirects.Core/Utilities/Caching/RedirectCacheRefresher.cs b/source/SimpleRedirects.Core/Utilities/Caching/RedirectCacheRefresher.cs
new file mode 100644
index 0000000..4f01c0e
--- /dev/null
+++ b/source/SimpleRedirects.Core/Utilities/Caching/RedirectCacheRefresher.cs
@@ -0,0 +1,25 @@
+using System;
+using SimpleRedirects.Core.Notifications;
+using Umbraco.Cms.Core.Cache;
+using Umbraco.Cms.Core.Events;
+
+namespace SimpleRedirects.Core.Utilities.Caching
+{
+ public class RedirectCacheRefresher : CacheRefresherBase
+ {
+ public static readonly Guid UniqueId = Guid.Parse("fe3847bc-80c4-4ce0-abde-551bb409599a");
+
+ public RedirectCacheRefresher(AppCaches appCaches, IEventAggregator eventAggregator, ICacheRefresherNotificationFactory factory) : base(appCaches, eventAggregator, factory)
+ {
+ }
+
+ public override Guid RefresherUniqueId => UniqueId;
+ public override string Name => "Redirects Cache Refresher";
+
+ public override void RefreshAll()
+ {
+ AppCaches.RuntimeCache.ClearByKey(RedirectRepository.CacheCategoryKey);
+ base.RefreshAll();
+ }
+ }
+}