Class Phalcon\Cache\Multiple

Allows to read to chained backends writing to multiple backends

  1. <?php
  2. use Phalcon\Cache\Frontend\Data as DataFrontend,
  3. Phalcon\Cache\Multiple,
  4. Phalcon\Cache\Backend\Apc as ApcCache,
  5. Phalcon\Cache\Backend\Memcache as MemcacheCache,
  6. Phalcon\Cache\Backend\File as FileCache;
  7. $ultraFastFrontend = new DataFrontend(array(
  8. "lifetime" => 3600
  9. ));
  10. $fastFrontend = new DataFrontend(array(
  11. "lifetime" => 86400
  12. ));
  13. $slowFrontend = new DataFrontend(array(
  14. "lifetime" => 604800
  15. ));
  16. //Backends are registered from the fastest to the slower
  17. $cache = new Multiple(array(
  18. new ApcCache($ultraFastFrontend, array(
  19. "prefix" => 'cache',
  20. )),
  21. new MemcacheCache($fastFrontend, array(
  22. "prefix" => 'cache',
  23. "host" => "localhost",
  24. "port" => "11211"
  25. )),
  26. new FileCache($slowFrontend, array(
  27. "prefix" => 'cache',
  28. "cacheDir" => "../app/cache/"
  29. ))
  30. ));
  31. //Save, saves in every backend
  32. $cache->save('my-key', $data);

Methods

public __construct ([unknown $backends])

Phalcon\Cache\Multiple constructor

public Phalcon\Cache\Multiple push (unknown $backend)

Adds a backend

public mixed get (unknown $keyName, [unknown $lifetime])

Returns a cached content reading the internal backends

public start (unknown $keyName, [unknown $lifetime])

Starts every backend

public save ([unknown $keyName], [unknown $content], [unknown $lifetime], [unknown $stopBuffer])

Stores cached content into all backends and stops the frontend

public boolean delete (unknown $keyName)

Deletes a value from each backend

public boolean exists ([unknown $keyName], [unknown $lifetime])

Checks if cache exists in at least one backend