* * 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:----NcejzgfXbbzNvWxDUZw5MO479/Op0qVwVqhBKjL+pNY81eZIJDwORPrp532eTMasYXIw2667PY91ebkbKJqt3xaNaRHMehpi1FwRuYM0Lri5nyui416+WojcaeBgUIjQPpwHVf945LDH2Q0oEt4Ci1EAM10JlB5CHQGtdUTk0vbY3RXSo60PCxSUY2/EQEKqRQ9/z8I1EHaggOkUWSFux663/tT8wH7y01ZO2W418ggwBnqy0mGkXZE3XgjKCtumFtu+9bZIqiv1y+LkZldZ+XVAsLAmPKD8/K4KF4tI2mgy8boYLbzJSHtukDQ803sCmH2S3vOoZIvvuQW1EOCTu7of/EBlPZrTvVuw56ypTsvLbBXzS6QhgFyw9b/oilqNnY1qTCRx4nI76EV91ATYUkQPNCApGGSyh1/M2jiDni7/srIwR/172qN4661hxE9F3lSjB1EpKcDpE/pBW/8rTthcO0qh/4/GfGnWZyV1JPYdGikUZHP796QJ3aGXLi4LgEs5hpnRd8jGQYoUZfd5C+VHXNlpUmvlnr4B/X0+fw2Tg6O7slLuEDcIcyfifnAPUFfivPrg7AAxHKdY97UcXgzwss9stfQbZPbDhHwJIgT8evje8ecHVkXrj2Quqzki/+AlQ/tWki2eeKzrO6BbUPthg4HEDC1omZ+P8sdOKA4=----ATTACHMENT:----OTUyMDIyMTM3ODg1ODcxMyA2NzIwNTcyODQ2NzE3NjQ0IDk5ODc0MTUxNTQwODEzOTI=