Looking at implementing some simple output caching on a multi tenant site (sites share the same codebase) and am wondering if people have a tried and tested way of doing this..
I have created a simple cache profile that varies by both url (varyByCustom) and by host (varyByHeader, to handle multiple root paths ['/']). This works lovely, and is nice and simple, but.. I want to be able to clear a URL from the cache when a node is published (preferably ONLY the URL of the updated node, I am not even sure you can blat the entire output cache in one hit?)
Now, I have a method attached to the
PageCacheRefresher.CacheUpdated
event, this is called just fine.. but.. how do I remove the correct item from the cache.
Normally you would call:
But, if saving a node with a different hostname, not sure how to go about clearing it, as RemoveOutputCacheItem only wants a virtual path, and I can't seem to target a specific hostname (at least I am unaware of how to..)
If there's a better package to use that I can do what I'd need, then would love to hear about it. Or am I doomed to roll my own solution, ignoring outputcache entirely and talking directly to the cache?
The key thing is how you construct the varyByCustom string. This gets inserted into the caching key. You can put any (string) data in here that you want then use it to selectively clear the cache later.
At OnActionExecuting you have access to UmbracoContext.Current.PublishedContentRequest.PublishedContent so you can use any properties you want from the document to selectively clear the cache. At the bare minimum I store the document Id and the Path (so you can clear parents and/or children as well).
I ultimately went down the route of writing a wrapper for the output cache that stores and parses small JSON encoded PoCOs in the varyByCustom string. We used JSON as it actually turned out quicker than processing the cache keys with methods like Containsint.TryParse(s) etc.
Outputcache in a multi-tenant site
Guys,
Looking at implementing some simple output caching on a multi tenant site (sites share the same codebase) and am wondering if people have a tried and tested way of doing this..
I have created a simple cache profile that varies by both url (varyByCustom) and by host (varyByHeader, to handle multiple root paths ['/']). This works lovely, and is nice and simple, but.. I want to be able to clear a URL from the cache when a node is published (preferably ONLY the URL of the updated node, I am not even sure you can blat the entire output cache in one hit?)
Now, I have a method attached to the
event, this is called just fine.. but.. how do I remove the correct item from the cache. Normally you would call:
But, if saving a node with a different hostname, not sure how to go about clearing it, as RemoveOutputCacheItem only wants a virtual path, and I can't seem to target a specific hostname (at least I am unaware of how to..)
If there's a better package to use that I can do what I'd need, then would love to hear about it. Or am I doomed to roll my own solution, ignoring outputcache entirely and talking directly to the cache?
All/any ideas welcome!
Thanks,
Mark
WRT Packages, take a look at MvCDonutCaching it will solve a lot of problems that you are about to have with things like navigation etc.
Paul Seal has a blog post on it with examples: https://codeshare.co.uk/blog/how-to-use-donut-caching-in-umbraco-and-mvc/
There's some example code from Dave Woestenborghs here too: https://gist.github.com/dawoe/f8d649c09f4f6341ea9630acbab44cf0
The key thing is how you construct the
varyByCustom
string. This gets inserted into the caching key. You can put any (string) data in here that you want then use it to selectively clear the cache later.At
OnActionExecuting
you have access toUmbracoContext.Current.PublishedContentRequest.PublishedContent
so you can use any properties you want from the document to selectively clear the cache. At the bare minimum I store the document Id and the Path (so you can clear parents and/or children as well).I ultimately went down the route of writing a wrapper for the output cache that stores and parses small JSON encoded PoCOs in the
varyByCustom
string. We used JSON as it actually turned out quicker than processing the cache keys with methods likeContains
int.TryParse(s)
etc.is working on a reply...