What is CI4 cache invalidation strategies?
Answer
Cache invalidation is one of the hardest problems in software — CI4 provides several strategies. Time-based expiry: set a TTL (time-to-live) and let cache expire naturally — simple but stale data is possible. Event-based invalidation: delete specific cache keys when data changes — use model callbacks (afterSave, afterDelete) to call cache()->delete("posts_list"). Cache tags (Redis/Memcached): group related items under a tag and invalidate the whole group: not natively in CI4 but achievable with custom logic. Cache versioning: include a version number in cache keys ("posts_v{$version}") and increment the version to invalidate. Page cache invalidation: cache()->delete(md5($url)) removes a specific page cache. Strategies: aggressive short TTL (simpler but more DB load), event invalidation (complex but data-accurate), or read-through caching with webhooks for external data.
Previous
What is CI4 model observer pattern?
Next
What is CodeIgniter 4 modular architecture patterns?