what you can do is to set the cacheDependencyKey and then remove that once you want to invalidate the cache
Hi Quan
Thank you for your replay and time.
So the process should look something like this?
CacheManager.Insert("cacheDependencyKey", new object());
search.StaticallyCacheFor(TimeSpan.FromMinutes(10), null, "cacheDependencyKey")
CacheManager.Remove("cacheDependencyKey");
search.StaticallyCacheFor(TimeSpan.FromMinutes(10), null, "cacheDependencyKey")
and if I understand it correctly, the best time to add the key to cache would be just right after I get the search result, right?
Petr
No you should add they cache dependency before you get the search result. So you got it almost right already, just think it should be like this on cache invalidation
CacheManager.Remove("cacheDependencyKey");
CacheManager.Add("cacheDependencyKey", new object());
Also if you want to nuke all the Find search result cache, you can remove CacheUtils.MasterKey
oh, now I get it! (and test it) This really invalidated the cache:
CacheManager.Remove("cacheDependencyKey");
CacheManager.Add("cacheDependencyKey", new object());
search.StaticallyCacheFor(TimeSpan.FromMinutes(10), null, "cacheDependencyKey")
Another question (which I can probable test) is if I set an expiration of that cachekey to let's say 5 minutes
new CacheEvictionPolicy(new TimeSpan(0, 5, 0), CacheTimeoutType.Absolute);
but the StaticallyCacheFor(TimeSpan.FromMinutes(10) is 10 minutes cache. I guess the cache will expire after 5 minutes, correct. The lowest time will just expire the cache here.
Thank you Quan!
IN theory, yes. the dependency key will expire after 5 minutes and the dependent caches will be removed too. My memory is a bit rusty but I think the general approach is to have the cache key object to live indefinitely (just like you add with just CacheManager.Add("cacheDependencyKey", new object()); ), so you only need to care about your StaticallyCacheFor time out.
Hi all,
I am not able to find any deeper information about how to invalidate cached results of "StaticallyCacheFor" in CMS 12.
It seems that I can use instance of IChangeToken. So I expected that just set the property HasChanged will be enough, but it is not working. I am still getting the cached result.
This is the method I am trying to use:
Do you have any advice how to use the IChangeToken and invalidate the cache result?