Class Phalcon\Cache\Frontend\Output

implements Phalcon\Cache\FrontendInterface

Source on GitHub

Allows to cache output fragments captured with ob_* functions

  1. <?php
  2. *
  3. * use Phalcon\Tag;
  4. * use Phalcon\Cache\Backend\File;
  5. * use Phalcon\Cache\Frontend\Output;
  6. *
  7. * // Create an Output frontend. Cache the files for 2 days
  8. * $frontCache = new Output(
  9. * [
  10. * "lifetime" => 172800,
  11. * ]
  12. * );
  13. *
  14. * // Create the component that will cache from the "Output" to a "File" backend
  15. * // Set the cache file directory - it's important to keep the "/" at the end of
  16. * // the value for the folder
  17. * $cache = new File(
  18. * $frontCache,
  19. * [
  20. * "cacheDir" => "../app/cache/",
  21. * ]
  22. * );
  23. *
  24. * // Get/Set the cache file to ../app/cache/my-cache.html
  25. * $content = $cache->start("my-cache.html");
  26. *
  27. * // If $content is null then the content will be generated for the cache
  28. * if (null === $content) {
  29. * // Print date and time
  30. * echo date("r");
  31. *
  32. * // Generate a link to the sign-up action
  33. * echo Tag::linkTo(
  34. * [
  35. * "user/signup",
  36. * "Sign Up",
  37. * "class" => "signup-button",
  38. * ]
  39. * );
  40. *
  41. * // Store the output into the cache file
  42. * $cache->save();
  43. * } else {
  44. * // Echo the cached output
  45. * echo $content;
  46. * }

Methods

public __construct ([array $frontendOptions])

Phalcon\Cache\Frontend\Output constructor

public getLifetime ()

Returns the cache lifetime

public isBuffering ()

Check whether if frontend is buffering output

public start ()

Starts output frontend. Currently, 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