Class Phalcon\Cache\Frontend\Igbinary

extends class Phalcon\Cache\Frontend\Data

implements Phalcon\Cache\FrontendInterface

Source on GitHub

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(
  4. [
  5. "lifetime" => 172800,
  6. ]
  7. );
  8. // Create the component that will cache "Igbinary" to a "File" backend
  9. // Set the cache file directory - important to keep the "/" at the end of
  10. // of the value for the folder
  11. $cache = new \Phalcon\Cache\Backend\File(
  12. $frontCache,
  13. [
  14. "cacheDir" => "../app/cache/",
  15. ]
  16. );
  17. $cacheKey = "robots_order_id.cache";
  18. // Try to get cached records
  19. $robots = $cache->get($cacheKey);
  20. if ($robots === null) {
  21. // $robots is null due to cache expiration or data do not exist
  22. // Make the database call and populate the variable
  23. $robots = Robots::find(
  24. [
  25. "order" => "id",
  26. ]
  27. );
  28. // Store it in the cache
  29. $cache->save($cacheKey, $robots);
  30. }
  31. // Use $robots :)
  32. foreach ($robots as $robot) {
  33. echo $robot->name, "\n";
  34. }

Methods

public __construct ([array $frontendOptions])

Phalcon\Cache\Frontend\Data constructor

public getLifetime ()

Returns the cache lifetime

public 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 beforeStore (mixed $data)

Serializes data before storing them

public afterRetrieve (mixed $data)

Unserializes data after retrieval