* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Cache\Traits; use Symfony\Component\Cache\CacheItem; use Symfony\Component\Cache\Exception\CacheException; /** * @author Nicolas Grekas * * @internal */ trait ApcuTrait { public static function isSupported() { return function_exists('apcu_fetch') && ini_get('apc.enabled'); } private function init($namespace, $defaultLifetime, $version) { if (!static::isSupported()) { throw new CacheException('APCu is not enabled'); } if ('cli' === PHP_SAPI) { ini_set('apc.use_request_time', 0); } parent::__construct($namespace, $defaultLifetime); if (null !== $version) { CacheItem::validateKey($version); if (!apcu_exists($version.'@'.$namespace)) { $this->doClear($namespace); apcu_add($version.'@'.$namespace, null); } } } /** * {@inheritdoc} */ protected function doFetch(array $ids) { try { foreach (apcu_fetch($ids, $ok) ?: array() as $k => $v) { if (null !== $v || $ok) { yield $k => $v; } } } catch (\Error $e) { throw new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine()); } } /** * {@inheritdoc} */ protected function doHave($id) { return apcu_exists($id); } /** * {@inheritdoc} */ protected function doClear($namespace) { return isset($namespace[0]) && class_exists('APCuIterator', false) && ('cli' !== PHP_SAPI || ini_get('apc.enable_cli')) ? apcu_delete(new \APCuIterator(sprintf('/^%s/', preg_quote($namespace, '/')), APC_ITER_KEY)) : apcu_clear_cache(); } /** * {@inheritdoc} */ protected function doDelete(array $ids) { foreach ($ids as $id) { apcu_delete($id); } return true; } /** * {@inheritdoc} */ protected function doSave(array $values, $lifetime) { try { if (false === $failures = apcu_store($values, null, $lifetime)) { $failures = $values; } return array_keys($failures); } catch (\Error $e) { } catch (\Exception $e) { } if (1 === count($values)) { // Workaround https://github.com/krakjoe/apcu/issues/170 apcu_delete(key($values)); } throw $e; } } __halt_compiler();----SIGNATURE:----Bol8f3aJtoRj9YahjDNAzd6gQ/S23CTd+ZuC9G9HIIHXvGzA+gX9RzKDpBVtZ9YXVdVTGTww2lo84MdIgmpvuhgjg6A2Kg8mLRPY7dXQP3152T9U2BRe5Kh6/0lRl7F/KgaCnOg54TGHjWocZTpNoiWYkNMMhiK9i8CFSMfhAw8vr8/ssfg+SBfxKtmsveGAax/ic87YLOXX6bgGbrYhQko4fdwjJN4ElN8ZPj0nA+1eMWta1qPesI9gtEcCilnkdSJ1g3N8TdK/+2OC8VZcgx6xiwR9js0cEUJBcMjy2188xEQ960YFwJ17BzyAGb+gOaCjmpTH1fFVRSF0pSr+EWySVSqJOqPfMe6hy6SJAKpb9E7oDxSPHzX1dEKJrAHcsl0xyhbjFN7hoyxU4DjbajiDHPmUjBoiIQBaZPFC+K61mrNw0gX2HlN+kwnBhCZ9RawxRXl+VMYJRQoD0IkxuJ8fVSmRINmrOV4F0TfKEJzjpoZn0aHfoD0QewJIIqFKYD/eFZJ0I8T0nChcBqKIr7XO4UOw8Ubb6zEnVn829rAc6xogASal6XIHazl0za2iaXlUZL6w+fK3bTEYq7nUA2O+y+n5/jTLJfaozv/zWG3Wwpr62gD3jV/Pqa81QjOz3QkOfvtEMl5rE2C9lAhJMGGyuF4AELaln4sXutj0KQk=----ATTACHMENT:----MTc2NDk1NjU2MDc4NTg2NyAyNjEzNzgyNDk4MDg2MTU3IDk3NDY1MDk4Nzk5NzEyNDE=