piranha.core
piranha.core copied to clipboard
Add cache dependency support
Right now, removing objects from the cache require creating and then removing many specific cache keys. I suggest we could implement cache dependency keys in the cache providers. Something like this:
- When adding data about a a blog post, we add the same cache keys as now. But we also add a virtual cache key for the blog post (without adding an object to it). The cache entries will need to name this virtual key as a dependency. Whenever we need to invalidate that blog post, we just remove that virtual key and all depending cache entries will be removed automatically.
- For blog post listings (e.g. getting an archive with different parameters) we could cache each filtered result with a virtual key (e.g. "BlogArchive_<BLOGID_HERE>") and use it for all cached listings. Whenever any blog posts in that blog archive is affected (added, deleted, published, unpublished, category or tags are updated), the virtual key will be removed from cache. This will instantly make all cached archive listings disappear from the cache. On next request data will again be loaded from the database.
It would clearly be a breaking change for a major version release. But how does it sound?