Deprecation: since version 1.6, use ApcuCache instead
Since: 2.0
Author: Benjamin Eberlei (kontakt@beberlei.de)
Author: Guilherme Blanco (guilhermeblanco@hotmail.com)
Author: Jonathan Wage (jonwage@gmail.com)
Author: Roman Borschel (roman@code-factory.org)
Author: David Abdemoulaie (dave@hobodave.com)
Inheritance: extends CacheProvider
Beispiel #1
0
 public function getMenu($type)
 {
     if ($this->environment == 'prod') {
         if ($this->appCache->contains('menu_' . $type)) {
             return unserialize($this->appCache->fetch('menu_' . $type));
         }
     }
     return $this->load($type);
 }
 /**
  * Creates cache by name.
  *
  * @param string $name    Name.
  * @param array  $options Options.
  *
  * @return CacheProvider
  * @throws \InvalidArgumentException When cache provider with given name not found.
  * @throws \LogicException When no caches provided for "chain" cache.
  */
 public function create($name, array $options = array())
 {
     switch ($name) {
         case 'chain':
             $valid_caches = array();
             foreach (array_filter($options) as $cache_name) {
                 $valid_caches[] = self::create($cache_name);
             }
             if (!$valid_caches) {
                 throw new \LogicException('No valid caches provided for "chain" cache.');
             }
             $cache_driver = new ChainCache($valid_caches);
             $cache_driver->setNamespace($this->_namespace);
             return $cache_driver;
         case 'array':
             $cache_driver = new ArrayCache();
             $cache_driver->setNamespace($this->_namespace);
             return $cache_driver;
         case 'apc':
             $cache_driver = new ApcCache();
             $cache_driver->setNamespace($this->_namespace);
             return $cache_driver;
         case 'memcache':
             $memcache = new \Memcache();
             $memcache->connect('localhost', 11211);
             $cache_driver = new MemcacheCache();
             $cache_driver->setMemcache($memcache);
             $cache_driver->setNamespace($this->_namespace);
             return $cache_driver;
         case 'memcached':
             $memcached = new \Memcached();
             $memcached->addServer('memcache_host', 11211);
             $cache_driver = new MemcachedCache();
             $cache_driver->setMemcached($memcached);
             $cache_driver->setNamespace($this->_namespace);
             return $cache_driver;
     }
     throw new \InvalidArgumentException('Cache provider "' . $name . '" not found.');
 }
 /**
  * {@inheritdoc}
  */
 protected function doFetch($id)
 {
     /** @var ClassMetadata $result */
     $classMetadata = parent::doFetch($id);
     if ($classMetadata instanceof ClassMetadata) {
         $className = $classMetadata->getName();
         $staticProperties = $classMetadata->getReflectionClass()->getStaticProperties();
         if (array_key_exists('_TSPEC', $staticProperties) && $staticProperties['_TSPEC'] === null) {
             new $className();
         }
     }
     return $classMetadata;
 }
 /**
  * Save cache by cacheID
  *
  * @param mixed (integer|string) $cacheID
  * @param array $weathers
  */
 private function saveCache($cacheID, $weather)
 {
     $this->appCache->save($cacheID, serialize($weather), 3600);
 }