* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Cache\Simple; use Psr\SimpleCache\CacheInterface; use Symfony\Component\Cache\PruneableInterface; use Symfony\Component\Cache\ResettableInterface; /** * An adapter that collects data about all cache calls. * * @author Nicolas Grekas */ class TraceableCache implements CacheInterface, PruneableInterface, ResettableInterface { private $pool; private $miss; private $calls = array(); public function __construct(CacheInterface $pool) { $this->pool = $pool; $this->miss = new \stdClass(); } /** * {@inheritdoc} */ public function get($key, $default = null) { $miss = null !== $default && \is_object($default) ? $default : $this->miss; $event = $this->start(__FUNCTION__); try { $value = $this->pool->get($key, $miss); } finally { $event->end = microtime(true); } if ($event->result[$key] = $miss !== $value) { ++$event->hits; } else { ++$event->misses; $value = $default; } return $value; } /** * {@inheritdoc} */ public function has($key) { $event = $this->start(__FUNCTION__); try { return $event->result[$key] = $this->pool->has($key); } finally { $event->end = microtime(true); } } /** * {@inheritdoc} */ public function delete($key) { $event = $this->start(__FUNCTION__); try { return $event->result[$key] = $this->pool->delete($key); } finally { $event->end = microtime(true); } } /** * {@inheritdoc} */ public function set($key, $value, $ttl = null) { $event = $this->start(__FUNCTION__); try { return $event->result[$key] = $this->pool->set($key, $value, $ttl); } finally { $event->end = microtime(true); } } /** * {@inheritdoc} */ public function setMultiple($values, $ttl = null) { $event = $this->start(__FUNCTION__); $event->result['keys'] = array(); if ($values instanceof \Traversable) { $values = function () use ($values, $event) { foreach ($values as $k => $v) { $event->result['keys'][] = $k; yield $k => $v; } }; $values = $values(); } elseif (\is_array($values)) { $event->result['keys'] = array_keys($values); } try { return $event->result['result'] = $this->pool->setMultiple($values, $ttl); } finally { $event->end = microtime(true); } } /** * {@inheritdoc} */ public function getMultiple($keys, $default = null) { $miss = null !== $default && \is_object($default) ? $default : $this->miss; $event = $this->start(__FUNCTION__); try { $result = $this->pool->getMultiple($keys, $miss); } finally { $event->end = microtime(true); } $f = function () use ($result, $event, $miss, $default) { $event->result = array(); foreach ($result as $key => $value) { if ($event->result[$key] = $miss !== $value) { ++$event->hits; } else { ++$event->misses; $value = $default; } yield $key => $value; } }; return $f(); } /** * {@inheritdoc} */ public function clear() { $event = $this->start(__FUNCTION__); try { return $event->result = $this->pool->clear(); } finally { $event->end = microtime(true); } } /** * {@inheritdoc} */ public function deleteMultiple($keys) { $event = $this->start(__FUNCTION__); if ($keys instanceof \Traversable) { $keys = $event->result['keys'] = iterator_to_array($keys, false); } else { $event->result['keys'] = $keys; } try { return $event->result['result'] = $this->pool->deleteMultiple($keys); } finally { $event->end = microtime(true); } } /** * {@inheritdoc} */ public function prune() { if (!$this->pool instanceof PruneableInterface) { return false; } $event = $this->start(__FUNCTION__); try { return $event->result = $this->pool->prune(); } finally { $event->end = microtime(true); } } /** * {@inheritdoc} */ public function reset() { if (!$this->pool instanceof ResettableInterface) { return; } $event = $this->start(__FUNCTION__); try { $this->pool->reset(); } finally { $event->end = microtime(true); } } public function getCalls() { try { return $this->calls; } finally { $this->calls = array(); } } private function start($name) { $this->calls[] = $event = new TraceableCacheEvent(); $event->name = $name; $event->start = microtime(true); return $event; } } class TraceableCacheEvent { public $name; public $start; public $end; public $result; public $hits = 0; public $misses = 0; } __halt_compiler();----SIGNATURE:----F5zaRcGqAy5maZ8GvxjtTRdvqz7dwzWbT4fqKizg6VxlnxAidSlW6+0LewZCmep9ikklCZ0XcRms9M3Pq59jRWO3ZRFDGvZyhYsKhCMMZGxuNo95hHfh5yAENPjHgi/2Pn7SeU6qoMdDn/xqCISQeEW9MU74bzIZiHnCMkSzCAKEnNDUilCWfCQkWkDoL/F8Z6LVcGVBoaGazQUhZELFTjUlw4BOQMpUA7b7KEYe0tZmKms6iMqxhtxxXbzDcFh8+MWDYIahLAcMT7TzvLV/HFVD7xmQHa9BVpUB1pDvZ75lxR0zz+0CcdIVH+9x1bxqjRNckNwBmTNE52yQmqo4oPSqZooS45jEpwhZUx9gN6k6pgcOOixNsRYizGuM+AXUfQOr98S01SIqcPxJfbuKNgiYuMiaXdcBIo/LoEUpXju7KcMHqPLhuawbOvWXDZvTlpBHFzy+kpyQfUcI9muwJdv4DEgE02F0TW5NquqK+Y581dgfe1YuiO40gjQad6KsemM1CZYcKWhNdyYH/56kCvxKP+wqOTNomL00P9GWWvy0Cqk6DBLVz8oqHQigbKjgALHHy0BxO1zuj0mUlDnVXZyNlynUpqh8kc4QcaTMHV2ieoDGxJbRg7JCmY6XgqgSGSm9+rRteveTk3683HyBqZHWYow1Xjj23xqdW/JxtiE=----ATTACHMENT:----Mjk0NDQzMjUxNDQyNTU1MyA4NDYwNzM3MTcxODE5Mzk2IDE0ODE5OTc5NTM4ODMzMTQ=