I want to add an object to our episerver cache that depends on a specific content item, and have it be removed from the cache automatically when the content item is republished.
I have gotten this to work, except only when using the global version key, not the version key for a specific content item. Using the global key is too aggressive. I'm hoping someone can clarify why this isn't working as expected.
// Filled correctly via service location: ISynchronizedObjectInstanceCache cache; IContentCacheKeyCreator cacheKeyCreator;
// Given: string key = "my-key"; string val = "some-object-that-depends-on-content"; ContentReference link = // reference to a specific content item... bool success = false;
cache.Insert(key, val, new CacheEvictionPolicy(new List { cacheKeyCreator.CreateVersionCommonCacheKey(link) })); success = cache.Get(key) != null; // nope...get back null...
cache.Insert(key, val, new CacheEvictionPolicy(new List { cacheKeyCreator.CreateVersionCacheKey(link) })); success = cache.Get(key) != null; // nope...get back null...
cache.Insert(key, val, new CacheEvictionPolicy(new List { cacheKeyCreator.VersionKey })); success = cache.Get(key) != null; // yes, this works and also gets removed from cache when content item gets republished // however: it also gets removed when any other content item gets republished, which seems too aggressive...
So it seems as though the first two options fail because the cache key returned by the cacheKeyCreator does not exist in the cache. If I add the generated key to the cache first, and then add my object, it will get inserted. However, it does not get removed when the content item gets republished, which I thought was the whole point of using the key generated by the cacheKeyCreator.
Can someone help me understand how to expire the cache correctly at a more granular level than the 'all content' version key?
I want to add an object to our episerver cache that depends on a specific content item, and have it be removed from the cache automatically when the content item is republished.
I have gotten this to work, except only when using the global version key, not the version key for a specific content item. Using the global key is too aggressive. I'm hoping someone can clarify why this isn't working as expected.
// Filled correctly via service location:
{ cacheKeyCreator.CreateVersionCommonCacheKey(link) }));
{ cacheKeyCreator.CreateVersionCacheKey(link) }));
{ cacheKeyCreator.VersionKey }));
ISynchronizedObjectInstanceCache cache;
IContentCacheKeyCreator cacheKeyCreator;
// Given:
string key = "my-key";
string val = "some-object-that-depends-on-content";
ContentReference link = // reference to a specific content item...
bool success = false;
cache.Insert(key, val, new CacheEvictionPolicy(new List
success = cache.Get(key) != null;
// nope...get back null...
cache.Insert(key, val, new CacheEvictionPolicy(new List
success = cache.Get(key) != null;
// nope...get back null...
cache.Insert(key, val, new CacheEvictionPolicy(new List
success = cache.Get(key) != null;
// yes, this works and also gets removed from cache when content item gets republished
// however: it also gets removed when any other content item gets republished, which seems too aggressive...
So it seems as though the first two options fail because the cache key returned by the cacheKeyCreator does not exist in the cache. If I add the generated key to the cache first, and then add my object, it will get inserted. However, it does not get removed when the content item gets republished, which I thought was the whole point of using the key generated by the cacheKeyCreator.
Can someone help me understand how to expire the cache correctly at a more granular level than the 'all content' version key?
Thanks!