Library to detect which Doctrine Cache system is available and determine the best to use.

v2.0 2014-04-07 20:39 UTC


Detects all available cache layers using Doctrine\Common\Cache

Also contains some performance data to select the best available Cache system.

This can be useful for varying development environments.


List all supported caches

use Lavoiesl\Doctrine\CacheDetector\CacheDetector;

$cache_detector = new CacheDetector;
$detectors = $cache_detector->getSupportedDetectors();

 * [Apc, Filesystem, PhpFile, etc.]

// Doctrine\Common\Cache\ApcCache
$cache = $detectors['Apc']->getCache();

Provide connection options

Provide options for the detector, see each detector for details.

$cache_detector->setConfig('Redis', array('port' => 1234));

// or

    'Redis' => array('port' => 1234),

Select best cache system

This will automatically select the most performant cache system with a requirement on the persistance level.

On a local machine, ArrayCache will suffice. On a production environment, you may want to require a distributed one.

use Lavoiesl\Doctrine\CacheDetector\Detector\AbstractDetector;

$array_cache    = $cache_detector->selectBest(AbstractDetector::PERSISTANCE_REQUEST)->getCache();
$apc_cache      = $cache_detector->selectBest(AbstractDetector::PERSISTANCE_LOCAL_SERVICE)->getCache();
$file_cache     = $cache_detector->selectBest(AbstractDetector::PERSISTANCE_LOCAL_PERMANENT)->getCache();
$memcache_cache = $cache_detector->selectBest(AbstractDetector::PERSISTANCE_DISTRIBUTED)->getCache();


  • Add support for MongoDB, Couchbase and Riak.
  • Add better data for performance