. */ namespace Doctrine\ORM\Cache\Region; use Doctrine\ORM\Cache\Lock; use Doctrine\ORM\Cache\Region; use Doctrine\ORM\Cache\CacheKey; use Doctrine\ORM\Cache\CacheEntry; use Doctrine\Common\Cache\CacheProvider; /** * The simplest cache region compatible with all doctrine-cache drivers. * * @since 2.5 * @author Fabio B. Silva */ class DefaultRegion implements Region { /** * @var \Doctrine\Common\Cache\CacheProvider */ protected $cache; /** * @var string */ protected $name; /** * @var integer */ protected $lifetime = 0; /** * @param string $name * @param \Doctrine\Common\Cache\CacheProvider $cache * @param integer $lifetime */ public function __construct($name, CacheProvider $cache, $lifetime = 0) { $this->cache = $cache; $this->name = (string) $name; $this->lifetime = (integer) $lifetime; $this->cache->setNamespace($this->name); } /** * {@inheritdoc} */ public function getName() { return $this->name; } /** * @return \Doctrine\Common\Cache\CacheProvider */ public function getCache() { return $this->cache; } /** * {@inheritdoc} */ public function contains(CacheKey $key) { return $this->cache->contains($this->name . '_' . $key->hash); } /** * {@inheritdoc} */ public function get(CacheKey $key) { return $this->cache->fetch($this->name . '_' . $key->hash) ?: null; } /** * {@inheritdoc} */ public function put(CacheKey $key, CacheEntry $entry, Lock $lock = null) { return $this->cache->save($this->name . '_' . $key->hash, $entry, $this->lifetime); } /** * {@inheritdoc} */ public function evict(CacheKey $key) { return $this->cache->delete($this->name . '_' . $key->hash); } /** * {@inheritdoc} */ public function evictAll() { return $this->cache->deleteAll(); } }