Doctrine Cache Adapter

Doctrine Cache Adapter

This adapter wraps any class extending the Doctrine Cache abstract provider, allowing you to use these providers in your application as if they were Symfony Cache adapters.

This adapter expects a \Doctrine\Common\Cache\CacheProvider instance as its first parameter, and optionally a namespace and default cache lifetime as its second and third parameters:

  1. use Doctrine\Common\Cache\CacheProvider;
  2. use Doctrine\Common\Cache\SQLite3Cache;
  3. use Symfony\Component\Cache\Adapter\DoctrineAdapter;
  4. $provider = new SQLite3Cache(new \SQLite3(__DIR__.'/cache/data.sqlite'), 'youTableName');
  5. $cache = new DoctrineAdapter(
  6. // a cache provider instance
  7. CacheProvider $provider,
  8. // a string prefixed to the keys of the items stored in this cache
  9. $namespace = '',
  10. // the default lifetime (in seconds) for cache items that do not define their
  11. // own lifetime, with a value 0 causing items to be stored indefinitely (i.e.
  12. // until the database table is truncated or its rows are otherwise deleted)
  13. $defaultLifetime = 0
  14. );

Tip

A Symfony\Component\Cache\DoctrineProvider class is also provided by the component to use any PSR6-compatible implementations with Doctrine-compatible classes.

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.