implements Phalcon\Cache\FrontendInterface
Allows to cache native PHP data in a serialized form
use Phalcon\Cache\Backend\File; use Phalcon\Cache\Frontend\Data; // Cache the files for 2 days using a Data frontend $frontCache = new Data( [ "lifetime" => 172800, ] ); // Create the component that will cache "Data" to a 'File' backend // Set the cache file directory - important to keep the '/' at the end of // of the value for the folder $cache = new File( $frontCache, [ "cacheDir" => "../app/cache/", ] ); $cacheKey = "robots_order_id.cache"; // Try to get cached records $robots = $cache->get($cacheKey); if ($robots === null) { // $robots is null due to cache expiration or data does not exist // Make the database call and populate the variable $robots = Robots::find( [ "order" => "id", ] ); // Store it in the cache $cache->save($cacheKey, $robots); } // Use $robots :) foreach ($robots as $robot) { echo $robot->name, "\n"; }
Phalcon\Cache\Frontend\Data constructor
Returns the cache lifetime
Check whether if frontend is buffering output
Starts output frontend. Actually, does nothing
Returns output cached content
Stops output frontend
Serializes data before storing them
Unserializes data after retrieval
© 2011–2017 Phalcon Framework Team
Licensed under the Creative Commons Attribution License 3.0.
https://docs.phalconphp.com/en/latest/api/Phalcon_Cache_Frontend_Data.html