4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Validator\Mapping\Cache;
14 use Doctrine\Common\Cache\Cache;
15 use Symfony\Component\Validator\Mapping\ClassMetadata;
18 * Adapts a Doctrine cache to a CacheInterface.
20 * @author Florian Voutzinos <florian@voutzinos.com>
22 final class DoctrineCache implements CacheInterface
27 * Creates a new Doctrine cache.
29 * @param Cache $cache The cache to adapt
31 public function __construct(Cache $cache)
33 $this->cache = $cache;
37 * Sets the cache to adapt.
39 * @param Cache $cache The cache to adapt
41 public function setCache(Cache $cache)
43 $this->cache = $cache;
49 public function has($class)
51 return $this->cache->contains($class);
57 public function read($class)
59 return $this->cache->fetch($class);
65 public function write(ClassMetadata $metadata)
67 $this->cache->save($metadata->getClassName(), $metadata);