Class Phalcon\Cache\Frontend\Output

implements Phalcon\Cache\FrontendInterface

Allows to cache output fragments captured with ob_* functions

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

Methods

public __construct ([unknown $frontendOptions])

Phalcon\Cache\Frontend\Output constructor

public integer getLifetime ()

Returns the cache lifetime

public boolean 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 string beforeStore (unknown $data)

Serializes data before storing them

public mixed afterRetrieve (unknown $data)

Unserializes data after retrieval