What is CI4 cache invalidation strategies?
Why Interviewers Ask This
Interviewers ask this to evaluate whether you have the depth of knowledge needed to mentor others and lead technical decisions. The expected answer goes beyond definitions into practical implications and real-world consequences.
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.
Pro Tip
Back up your answer with a specific project or situation. Saying 'In my last CodeIgniter project, I used this when...' immediately makes your answer more credible and memorable.
Previous
What is CI4 model observer pattern?
Next
What is CodeIgniter 4 modular architecture patterns?