/**
  * @return mixed|null
  * @throws \InvalidArgumentException
  */
 public function commit()
 {
     /**
      * @eventName CacheCommitItem
      * @param $this ExtendedCacheItemPoolInterface
      * @param $deferredList ExtendedCacheItemInterface[]
      */
     $this->eventManager->dispatch('CacheCommitItem', $this, $this->deferredList);
     $return = null;
     foreach ($this->deferredList as $key => $item) {
         $result = $this->save($item);
         if ($return !== false) {
             unset($this->deferredList[$key]);
             $return = $result;
         }
     }
     return (bool) $return;
 }
Beispiel #2
0
 /**
  * @param string $driver
  * @param array $config
  * @return ExtendedCacheItemPoolInterface
  * @throws phpFastCacheDriverCheckException
  */
 public static function getInstance($driver = 'auto', $config = [])
 {
     static $badPracticeOmeter = [];
     /**
      * @todo: Standardize a method for driver name
      */
     $driver = self::standardizeDriverName($driver);
     $config = array_merge(self::$config, $config);
     if (!$driver || $driver === 'Auto') {
         $driver = self::getAutoClass($config);
     }
     $instance = crc32($driver . serialize($config));
     if (!isset(self::$instances[$instance])) {
         $badPracticeOmeter[$driver] = 1;
         if (!$config['ignoreSymfonyNotice'] && interface_exists('Symfony\\Component\\HttpKernel\\KernelInterface') && !class_exists('phpFastCache\\Bundle\\phpFastCacheBundle')) {
             trigger_error('A Symfony Bundle to make the PhpFastCache integration more easier is now available here: https://github.com/PHPSocialNetwork/phpfastcache-bundle', E_USER_NOTICE);
         }
         $class = self::getNamespacePath() . $driver . '\\Driver';
         try {
             self::$instances[$instance] = new $class($config);
             self::$instances[$instance]->setEventManager(EventManager::getInstance());
         } catch (phpFastCacheDriverCheckException $e) {
             $fallback = self::standardizeDriverName($config['fallback']);
             if ($fallback && $fallback !== $driver) {
                 $class = self::getNamespacePath() . $fallback . '\\Driver';
                 self::$instances[$instance] = new $class($config);
                 self::$instances[$instance]->setEventManager(EventManager::getInstance());
                 trigger_error(sprintf('The "%s" driver is unavailable at the moment, the fallback driver "%s" has been used instead.', $driver, $fallback), E_USER_WARNING);
             } else {
                 throw new phpFastCacheDriverCheckException($e->getMessage(), $e->getCode(), $e);
             }
         }
     } else {
         if (++$badPracticeOmeter[$driver] >= 5) {
             trigger_error('[' . $driver . '] Calling many times CacheManager::getInstance() for already instanced drivers is a bad practice and have a significant impact on performances.
        See https://github.com/PHPSocialNetwork/phpfastcache/wiki/[V5]-Why-calling-getInstance%28%29-each-time-is-a-bad-practice-%3F');
         }
     }
     return self::$instances[$instance];
 }