ApcCache.php 823 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace Symfony\Component\Validator\Mapping\Cache;
  3. use Symfony\Component\Validator\Mapping\ClassMetadata;
  4. class ApcCache implements CacheInterface
  5. {
  6. private $prefix;
  7. public function __construct($prefix)
  8. {
  9. if (!extension_loaded('apc')) {
  10. throw new \RuntimeException('First you need to enable APC extension in your php.ini. In meanwhile you can just remove "cache" option from application configuration.');
  11. }
  12. $this->prefix = $prefix;
  13. }
  14. public function has($class)
  15. {
  16. return apc_exists($this->prefix.$class);
  17. }
  18. public function read($class)
  19. {
  20. return apc_fetch($this->prefix.$class);
  21. }
  22. public function write(ClassMetadata $metadata)
  23. {
  24. apc_store($this->prefix.$metadata->getClassName(), $metadata);
  25. }
  26. }