November Happy Hour will be moved to Thursday December 5th.

Unable to invalidated FIND (Search & Navihgation) cache results with a dependency (cacheDependencyKey) in CMS 12/.NET Core

Vote:
 

In CMS 11 CacheDependency used to do the job for me 

var cacheDependency = new CacheDependency(null, new[] { Global.CacheKeys.SomeKey });
var results = query.StaticallyCacheFor(TimeSpan.FromMinutes(60), cacheDependency).GetContentResult();

and invalidate the cache on PublishingContent event of the page 

private readonly ISynchronizedObjectInstanceCache _cache;
public CacheService(ISynchronizedObjectInstanceCache cache)
{
    _cache = cache;
}
....
public void OnContentChange(string cacheKey)
{
    _cache.RemoveLocal(cacheKey);
    _cache.RemoveRemote(cacheKey);
}

As CacheDependency is not supported in .Net Core/CMS12

my current code looks like this.NetCore

var results= query.StaticallyCacheFor(TimeSpan.FromMinutes(60), null, Global.CacheKeys.SomeKey);

I am trying to invalidate the cache using the above code on the PublishingContent event but the FIND cache doesn't get invalidating. I have gone as far as removing all the FIND cache keys from MemeoryCache but still don't get the correct results. 

Can someone help in solving this issue?

#309652
Sep 28, 2023 15:52
Vote:
 

Can you get instance of ICache and see if it is indeed CmsRunTimeCacheAdapter ?

#309688
Sep 29, 2023 6:18
Rich Hallman - Sep 29, 2023 9:47
yes, it is the instance of EPiServer.Find.Cms.CmsRunTimeCacheAdapter
Quan Mai - Sep 29, 2023 10:37
hmm, then I'm out of idea. I've forwarded this question to someone who knows Find better than me - will get back
Vote:
 

I got the feedback, and it seems to be all working 

Sample code

public void TestStaticallyCache(IObjectInstanceCache cache)
{
    var cacheKey = "blahaKey";

 

    cache.Insert(cacheKey, new object(), CacheEvictionPolicy.Empty);    

 

 

    SearchClient.Instance.Search<PageData>()
        .StaticallyCacheFor(TimeSpan.FromDays(1000), null, cacheKey)
        .GetContentResult();

 

    SearchClient.Instance.Search<PageData>()
        .StaticallyCacheFor(TimeSpan.FromDays(1000), null, cacheKey)
        .GetContentResult();

 

    cache.Remove(cacheKey);
    cache.Insert(cacheKey, new object(), CacheEvictionPolicy.Empty);

 

 

    SearchClient.Instance.Search<PageData>()
        .StaticallyCacheFor(TimeSpan.FromDays(1000), null, cacheKey)
        .GetContentResult();
}

#309836
Oct 02, 2023 11:18
Vote:
 

@Quan Mai The above code will only function as intended (still with a 10-15 second delay), if there exists a valid cache entry prior to the FIND query

   cache.Insert(cacheKey, new object(), CacheEvictionPolicy.Empty);    

My initial belief was that by utilizing StaticallyCacheFor with a cacheDependencyKey and subsequently invalidating it during the PublishingContent event, the FIND operation would automatically invalidate its own cache using the same key.

#309888
Oct 03, 2023 8:58
Vote:
 

Now I looked into IObjectInstanceCache implementation in CMS 12 and it no longer requires the cache key to have existing object, like in 11. So it should just work. I suggest to contact developer service, maybe cc Karl and we can look into reproducing this issue. 

#309889
Oct 03, 2023 9:18
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.