Class Phalcon\Cache\Frontend\Data

implements Phalcon\Cache\FrontendInterface

Allows to cache native PHP data in a serialized form

  1. <?php
  2. <?php
  3. // Cache the files for 2 days using a Data frontend
  4. $frontCache = new \Phalcon\Cache\Frontend\Data(array(
  5. "lifetime" => 172800
  6. ));
  7. // Create the component that will cache "Data" to a "File" backend
  8. // Set the cache file directory - important to keep the "/" at the end of
  9. // of the value for the folder
  10. $cache = new \Phalcon\Cache\Backend\File($frontCache, array(
  11. "cacheDir" => "../app/cache/"
  12. ));
  13. // Try to get cached records
  14. $cacheKey = 'robots_order_id.cache';
  15. $robots = $cache->get($cacheKey);
  16. if ($robots === null) {
  17. // $robots is null due to cache expiration or data does not exist
  18. // Make the database call and populate the variable
  19. $robots = Robots::find(array("order" => "id"));
  20. // Store it in the cache
  21. $cache->save($cacheKey, $robots);
  22. }
  23. // Use $robots :)
  24. foreach ($robots as $robot) {
  25. echo $robot->name, "\n";
  26. }

Methods

public __construct ([unknown $frontendOptions])

Phalcon\Cache\Frontend\Data constructor

public integer getLifetime ()

Returns the cache lifetime

public boolean isBuffering ()

Check whether if frontend is buffering output

public start ()

Starts output frontend. Actually, does nothing

public string getContent ()

Returns output cached content

public stop ()

Stops output frontend

public string beforeStore (unknown $data)

Serializes data before storing them

public mixed afterRetrieve (unknown $data)

Unserializes data after retrieval