I’ve seen a number of Sitecore projects now that use the ASP.NET cache, and this bothers me slightly. Shouldn’t Sitecore – which does have it’s own caching – offer a way of caching itself? Perhaps with integration to things like ‘clear cache on publish’, etc.?
Well, it does, and Anders Laub describes it neatly in “How to create a custom cache in Sitecore“.
The TL;DR version is:
- Create a subclass of CustomCache
- Implement a Constructor that calls the Base constructor with a name and maximum size.
- Create a cache object that implements ICacheable
- Wrap access to the cache in a Static class with Get() and Set() methods
It’s a good post that one, well worth reading.