Class Phalcon\Cache\Frontend\Base64

implements Phalcon\Cache\FrontendInterface

Allows to cache data converting/deconverting them to base64. This adapter uses the base64_encode/base64_decode PHP’s functions

  1. <?php
  2. <?php
  3. // Cache the files for 2 days using a Base64 frontend
  4. $frontCache = new \Phalcon\Cache\Frontend\Base64(array(
  5. "lifetime" => 172800
  6. ));
  7. //Create a MongoDB cache
  8. $cache = new \Phalcon\Cache\Backend\Mongo($frontCache, array(
  9. 'server' => "mongodb://localhost",
  10. 'db' => 'caches',
  11. 'collection' => 'images'
  12. ));
  13. // Try to get cached image
  14. $cacheKey = 'some-image.jpg.cache';
  15. $image = $cache->get($cacheKey);
  16. if ($image === null) {
  17. // Store the image in the cache
  18. $cache->save($cacheKey, file_get_contents('tmp-dir/some-image.jpg'));
  19. }
  20. header('Content-Type: image/jpeg');
  21. echo $image;

Methods

public __construct ([unknown $frontendOptions])

Phalcon\Cache\Frontend\Base64 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