Hey guys, I'm keen to use the new HybridCache API with Xperience and am looking for a bit of guidance and to gauge the consensus around multilevel caching in general.
For those unaware: HybridCache library in ASP.NET Core | Microsoft Learn
HybridCaching combines an in-memory cache (L1) with a distributed caching solution (L2). This has a number of benefits over a traditional single tier cache:
- Fast cache item access via L1 in memory store
- High availability and resilience to server restarts, deployments etc...
- Scalability across multiple nodes
This is all great, but the only problem is HybridCache is still in preview, and is missing a lot of key features which would be required for a successful integration, in particular:
A way to invalidate cache
- There is a 'RemoveByTag' method which would be ideal for this (tags being equivalent to a kentico dummy cache key) however this feature hasn't been implemented yet
- HybridCache library in ASP.NET Core | Microsoft Learn
A way to synchronise changes between nodes
- We would also need a way of synchronizing L1 cache changes between each node in a scaled out scenario
I have a custom solution for tagging cache entries in place already, so that leaves the synchronization issue, which I believe I can solve using either of these approaches:
Custom web farm task
- Create a custom web farms task which is pushed in response to some CMS action such as updating a page or object
- The task would contain a collection of dummy keys specific to that object
- Each running node would then receive the dummy keys and handle invalidation of its own L1 cache
- Only issue is it appears custom web farms tasks are not officially supported in Xperience, although the API for them still exists
Use redis pub/sub
- We could use redis pub/sub pattern to synchronise changes between nodes
- We would designate a specific instance (could be the CMS) as the publisher, who publishes to a cache sync channel
- The subscribers (frontend instances) would listen to this channel for messages containing dummy keys to invalidate
These are the challenges I'm currently faced with if I opt to use the new HybridCache API, however I've also come across an alternative package which is more mature, and offers many of the same features as HybridCache and more.
FusionCache:
https://github.com/ZiggyCreatures/FusionCache
For a comparison with HybridCache:
https://github.com/ZiggyCreatures/FusionCache/blob/main/docs/Comparison.md
This appears to do everything needed and has some other useful features such as automatic failsafes and fallback to stale content in the event of errors.
In particular, it implements it's own 'RemoveByTag' functionality as well as a cache 'backplane' for syncing changes to each nodes L1 cache (which I believe uses redis pub/sub under the hood), so this solves the primary issues I'm facing with HybridCache.
I will just summarise my question with the below points:
- Do you have any thoughts on Hybrid Caching in general to share, or on either of the approaches I've outlined above (.NET HybridCache or FusionCache)?
- Is this something Kentico are considering integrating into Xperience themselves and perhaps they’re waiting for HybridCache to mature? I do know that Umbraco have already added it to their latest version.
- Would you use Hybrid Caching at all or just stick with a single in memory cache and keep things simple?
Thanks