Try our conversational search powered by Generative AI!

"DataFactoryCache.Version" cache dependency in a load balanced environment

Vote:
 

Hi,

I noticed that when using "DataFactoryCache.Version" cache dependency in a load balanced environment, sometimes the caching stopped working completely. After some debugging I found the reason; the entry "DataFactoryCache.Version" was not present in the cache, and if a cache dependency is not present, the entry is not cached at all.

It seems that when a remote cache is updated, the"DataFactoryCache.Version" entry is removed completely, whereas with local cache it is updated.

One simple workaround is to ensure that the dependency is present before inserting the entry. Little code digging revealed that getting DataFactoryCache.Version property has side-effects which ensure the dependency is cached (both in 9.0.0 and 9.7.2, though the inner workings differ a lot). So, we can wrap-up the workaround like this:

    private static CacheEvictionPolicy CreateCacheEvictionPolicy(int cacheTimeSeconds)
    {
        // DataFactoryCache.VersionKey must exists in the cache. Otherwise 
        // the entries are not cached (the key is removed when a remote server 
        // content is updated).
        // Version call ensures that the key is present
        var version = DataFactoryCache.Version;
        
        return new CacheEvictionPolicy(new[] { DataFactoryCache.VersionKey }, 
                                      TimeSpan.FromSeconds(cacheTimeSeconds), 
                                      CacheTimeoutType.Absolute);
    }

With this I can fix custom caching issues. But from what I can tell, it looks that EPiServer.Find.Cms.SearchRequestExtensions.GetContentResult is also affected by the same issue.

Have you noticed this issue, and if so, what workarounds have you applied? I was thinking that if this is a common issue, then perhaps Episerver might update the cache version on remote servers when they receive remote cache removal event. 

#145893
Mar 15, 2016 0:38
Vote:
 

NB! In the latest Episerver version (9.7.2) DataFactoryCache is marked deprecated, and the VersionKey should be retrieved from IContentCacheKeyCreator.VersionKey property instead of static DataFactoryCache.VersionKey. But this should not be an issue because the old interfaces are now wrappers for new implementations and the VersionKey is still the same. The reason I am sticking with the old is to keep 9.x compatibility with our Nuget packages that use caching: 

#145894
Mar 15, 2016 1:05
Vote:
 

This bug (FIND-3039) is fixed in upcoming Find 13.1.0.

#192343
May 15, 2018 15:08
* 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.