* * 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:----EuQUuVqTw4JLqRFMC43cCNh+2IZWY77aBd5UcY8yFa+NXXIJYKFZofSYdaKeJmc5vQft4AuMICr5N4jwsEcBLKgnmfq+X1zlucNP7o+HkptwUA4H7b5T/TlZ/js7Bj0kD/1SZDxLd5x7CBKFxyoMBdu4E0iMXyNbdtoAlaxbLVIWnzv5+vO+s2JB9c84O8cUTi+58CVz0GagG8hAZN6KjWF9oenMcgZRCSJ1c6hhxUQlQMfPn9a4EMWiyk5c4r8XEqzAL4ZQmnkCZAjh8b+z9OvTB6xPlKiENMYzME5rrWLeVTWmBXY3GKAfLyZMGbHKQ68hD2hUFlZcECSEKQ6equHnh89F6Iqw9GGCQvpZGCgZ1WcJ10RtA6FfhKZ1xJyWlCt7Szlvfg/GvM+aV59zHvp8TEvmYFkqJyZWWlnJ9Rimx4e+2eg+VoA9kwhGnclef63X40p5GflmSCH8NC7wz0c08TpUhyNAZah6yNOZ13k+SOOSNinUyCYPO91xSzxXlbE7osiimLEao9a0fioTniHnlDm4tujHu5oWZOsEunapU/Gtz9EtJI0XPIlAj1p9hhu1hEulcA/ikJrxlydwVdUidMiM7xUMf4fGsrOlgegxIo9QWu+zdnJbf/5GHeKoWxTPJbHYOyel2m4Pooir/zoYqktlnSOCMPtYAOZJCTs=----ATTACHMENT:----MjUxOTM4MDA5NDk1OTkzNSAzMTk2MDUxMDQ5MjY0Mzc1IDEyMjkyODE0NzM2Njk5MTg=