Class Phalcon\Cache\Frontend\Base64

implements Phalcon\Cache\FrontendInterface

Source on GitHub

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(
  5. [
  6. "lifetime" => 172800,
  7. ]
  8. );
  9. //Create a MongoDB cache
  10. $cache = new \Phalcon\Cache\Backend\Mongo(
  11. $frontCache,
  12. [
  13. "server" => "mongodb://localhost",
  14. "db" => "caches",
  15. "collection" => "images",
  16. ]
  17. );
  18. $cacheKey = "some-image.jpg.cache";
  19. // Try to get cached image
  20. $image = $cache->get($cacheKey);
  21. if ($image === null) {
  22. // Store the image in the cache
  23. $cache->save(
  24. $cacheKey,
  25. file_get_contents("tmp-dir/some-image.jpg")
  26. );
  27. }
  28. header("Content-Type: image/jpeg");
  29. echo $image;

Methods

public __construct ([array $frontendOptions])

Phalcon\Cache\Frontend\Base64 constructor

public getLifetime ()

Returns the cache lifetime

public isBuffering ()

Check whether if frontend is buffering output

public start ()

Starts output frontend. Actually, does nothing in this adapter

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