Data Caching
Data Caching
Data caching is about storing some PHP variables in cache and retrieving it later from cache. It is also the foundation for more advanced caching features, such as query caching and page caching.
The following code is a typical usage pattern of data caching, where $cache
refers to a cache component:
// try retrieving $data from cache $data = $cache->get($key); if ($data === false) { // $data is not found in cache, calculate it from scratch $data = $this->calculateSomething(); // store $data in cache so that it can be retrieved next time $cache->set($key, $data); } // $d