🔥 CodeIgniter Intermediate

What is CodeIgniter 4's Caching system?

Why Interviewers Ask This

Mid-level CodeIgniter roles require deep understanding of this topic. Interviewers ask this to separate candidates who truly understand the mechanics from those who only know surface-level concepts.

Answer

CodeIgniter 4 provides a unified caching API supporting multiple drivers. Configure in app/Config/Cache.php: set $handler = "redis" (or file, memcached, wincache, dummy). Get the cache service: $cache = service("cache"). Save: $cache->save("key", $data, 3600) (TTL in seconds). Get: $cache->get("key") — returns null if not found or expired. Delete: $cache->delete("key"). Clean all: $cache->clean(). Check if cached: $cache->getCacheInfo("key"). Common pattern: if (!$data = $cache->get("key")) { $data = $this->model->getExpensiveData(); $cache->save("key", $data, 3600); }. Cache entire page output with CI4's Page Cache: $this->cachePage(300) in a controller caches the full HTML response for 300 seconds.

Common Mistake

A common mistake is memorizing definitions without understanding implications. When asked this question, go one level deeper — explain what happens when this concept is misused or ignored.