2025-04-24 13:15:30 +02:00
|
|
|
using NUnit.Framework;
|
|
|
|
|
using Umbraco.Cms.Core.Cache;
|
|
|
|
|
using Umbraco.Cms.Core.Services.Changes;
|
|
|
|
|
using Umbraco.Cms.Infrastructure.HybridCache;
|
|
|
|
|
using Umbraco.Cms.Tests.Common.Testing;
|
|
|
|
|
using Umbraco.Cms.Tests.Integration.Testing;
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Cache;
|
|
|
|
|
|
|
|
|
|
// We need to make sure that it's the distributed cache refreshers that refresh the elements cache
|
|
|
|
|
// see: https://github.com/umbraco/Umbraco-CMS/issues/18467
|
|
|
|
|
[TestFixture]
|
|
|
|
|
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerFixture)]
|
|
|
|
|
internal sealed class DistributedCacheRefresherTests : UmbracoIntegrationTest
|
|
|
|
|
{
|
|
|
|
|
private IElementsCache ElementsCache => GetRequiredService<IElementsCache>();
|
|
|
|
|
|
|
|
|
|
private ContentCacheRefresher ContentCacheRefresher => GetRequiredService<ContentCacheRefresher>();
|
|
|
|
|
|
|
|
|
|
private MediaCacheRefresher MediaCacheRefresher => GetRequiredService<MediaCacheRefresher>();
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void DistributedContentCacheRefresherClearsElementsCache()
|
|
|
|
|
{
|
|
|
|
|
var cacheKey = "test";
|
|
|
|
|
PopulateCache("test");
|
|
|
|
|
|
2025-10-08 14:55:50 +02:00
|
|
|
ContentCacheRefresher.RefreshInternal([new ContentCacheRefresher.JsonPayload()]);
|
2025-04-24 13:15:30 +02:00
|
|
|
ContentCacheRefresher.Refresh([new ContentCacheRefresher.JsonPayload()]);
|
|
|
|
|
|
|
|
|
|
Assert.IsNull(ElementsCache.Get(cacheKey));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void DistributedMediaCacheRefresherClearsElementsCache()
|
|
|
|
|
{
|
|
|
|
|
var cacheKey = "test";
|
|
|
|
|
PopulateCache("test");
|
|
|
|
|
|
2025-10-08 14:55:50 +02:00
|
|
|
MediaCacheRefresher.RefreshInternal([new MediaCacheRefresher.JsonPayload(1, Guid.NewGuid(), TreeChangeTypes.RefreshAll)]);
|
2025-04-24 13:15:30 +02:00
|
|
|
MediaCacheRefresher.Refresh([new MediaCacheRefresher.JsonPayload(1, Guid.NewGuid(), TreeChangeTypes.RefreshAll)]);
|
|
|
|
|
|
|
|
|
|
Assert.IsNull(ElementsCache.Get(cacheKey));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void PopulateCache(string key)
|
|
|
|
|
{
|
|
|
|
|
ElementsCache.Get(key, () => new object());
|
|
|
|
|
|
|
|
|
|
// Just making sure something is in the cache now.
|
|
|
|
|
Assert.IsNotNull(ElementsCache.Get(key));
|
|
|
|
|
}
|
|
|
|
|
}
|