Hey everyone! I need help with Redis caching on my WordPress multisite network. I’m currently using a Redis caching plugin but I want more granular control over cache invalidation.
My current situation:
Large multisite installation with custom post types
Redis object caching is working but feels too generic
Need better cache management when CPTs get updated
Want to control caching behavior for REST API calls
What I’m trying to achieve:
Custom cache invalidation rules based on post type changes
Better cache synchronization between different sites in the network
Hooks or filters to manually control cache purging
Has anyone built a custom caching strategy like this? I’m looking for advice on WordPress hooks I should use and best practices for multisite cache management.
Any code examples or plugin recommendations would be awesome!
I’ve tackled similar multisite Redis issues before. Custom cache groups are the way to go here. Use wp_cache_set() and wp_cache_delete() with site-specific groups instead of the default setup. For CPT invalidation, hook into save_post and delete_post actions. Build your own cache key convention with site ID and post type - something like site_{blog_id}_{post_type}_{post_id} gives you that granular control. For REST API caching, I use rest_pre_dispatch to check for cached responses and rest_post_dispatch to store them. wp_cache_flush_group() works great when you need to target specific groups after content changes network-wide. Pro tip: build a custom cache manager class to handle which keys get invalidated based on post relationships and taxonomy changes. Beats flushing everything like a shotgun.
hey, I feel ya! for more control, check out clean_post_cache and clean_object_cache when updating CPTs. also, using wp_cache_flush_group() can help manage site-specific caching. hope that helps!
Building a custom invalidation system for multisite Redis means intercepting cache operations at the right spots. I built something similar by extending the default Redis object cache class and overriding the delete method to handle cross-site dependencies. The key is using switch_to_blog() when you need to invalidate related content on other sites in your network. For REST API integration, build your own transient-based cache layer that sits between Redis and the API endpoints. You can use pre_get_posts to detect when queries might affect cached API responses, then trigger selective purges. The wp_cache_add_non_persistent_groups() function is super useful for API data that doesn’t need to survive between requests but needs Redis speed during a single request cycle. Don’t forget to account for user capabilities when caching API responses - there’s nothing worse than serving admin-only data to regular users because you cached too aggressively.