Class Phalcon\Cache\Frontend\Igbinary

extends class Phalcon\Cache\Frontend\Data

implements Phalcon\Cache\FrontendInterface

Allows to cache native PHP data in a serialized form using igbinary extension

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

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