* @author Tobias Nyholm * @author Nicolas Grekas */ class TraceableAdapter implements AdapterInterface, CacheInterface, PruneableInterface, ResettableInterface { protected $pool; private $calls = []; public function __construct(AdapterInterface $pool) { $this->pool = $pool; } /** * {@inheritdoc} */ public function get(string $key, callable $callback, float $beta = null, array &$metadata = null) { if (!$this->pool instanceof CacheInterface) { throw new \BadMethodCallException(sprintf('Cannot call "%s::get()": this class doesn\'t implement "%s".', get_debug_type($this->pool), CacheInterface::class)); } $isHit = true; $callback = function (CacheItem $item, bool &$save) use ($callback, &$isHit) { $isHit = $item->isHit(); return $callback($item, $save); }; $event = $this->start(__FUNCTION__); try { $value = $this->pool->get($key, $callback, $beta, $metadata); $event->result[$key] = get_debug_type($value); } finally { $event->end = microtime(true); } if ($isHit) { ++$event->hits; } else { ++$event->misses; } return $value; } /** * {@inheritdoc} */ public function getItem($key) { $event = $this->start(__FUNCTION__); try { $item = $this->pool->getItem($key); } finally { $event->end = microtime(true); } if ($event->result[$key] = $item->isHit()) { ++$event->hits; } else { ++$event->misses; } return $item; } /** * {@inheritdoc} * * @return bool */ public function hasItem($key) { $event = $this->start(__FUNCTION__); try { return $event->result[$key] = $this->pool->hasItem($key); } finally { $event->end = microtime(true); } } /** * {@inheritdoc} * * @return bool */ public function deleteItem($key) { $event = $this->start(__FUNCTION__); try { return $event->result[$key] = $this->pool->deleteItem($key); } finally { $event->end = microtime(true); } } /** * {@inheritdoc} * * @return bool */ public function save(CacheItemInterface $item) { $event = $this->start(__FUNCTION__); try { return $event->result[$item->getKey()] = $this->pool->save($item); } finally { $event->end = microtime(true); } } /** * {@inheritdoc} * * @return bool */ public function saveDeferred(CacheItemInterface $item) { $event = $this->start(__FUNCTION__); try { return $event->result[$item->getKey()] = $this->pool->saveDeferred($item); } finally { $event->end = microtime(true); } } /** * {@inheritdoc} */ public function getItems(array $keys = []) { $event = $this->start(__FUNCTION__); try { $result = $this->pool->getItems($keys); } finally { $event->end = microtime(true); } $f = function () use ($result, $event) { $event->result = []; foreach ($result as $key => $item) { if ($event->result[$key] = $item->isHit()) { ++$event->hits; } else { ++$event->misses; } yield $key => $item; } }; return $f(); } /** * {@inheritdoc} * * @return bool */ public function clear(string $prefix = '') { $event = $this->start(__FUNCTION__); try { if ($this->pool instanceof AdapterInterface) { return $event->result = $this->pool->clear($prefix); } return $event->result = $this->pool->clear(); } finally { $event->end = microtime(true); } } /** * {@inheritdoc} * * @return bool */ public function deleteItems(array $keys) { $event = $this->start(__FUNCTION__); $event->result['keys'] = $keys; try { return $event->result['result'] = $this->pool->deleteItems($keys); } finally { $event->end = microtime(true); } } /** * {@inheritdoc} * * @return bool */ public function commit() { $event = $this->start(__FUNCTION__); try { return $event->result = $this->pool->commit(); } 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 ResetInterface) { $this->pool->reset(); } $this->clearCalls(); } /** * {@inheritdoc} */ public function delete(string $key): bool { $event = $this->start(__FUNCTION__); try { return $event->result[$key] = $this->pool->deleteItem($key); } finally { $event->end = microtime(true); } } public function getCalls() { return $this->calls; } public function clearCalls() { $this->calls = []; } protected function start(string $name) { $this->calls[] = $event = new TraceableAdapterEvent(); $event->name = $name; $event->start = microtime(true); return $event; } } class TraceableAdapterEvent { public $name; public $start; public $end; public $result; public $hits = 0; public $misses = 0; } __halt_compiler();----SIGNATURE:----fII3UsxErk2xjhtUoGAkanCe+ABo7eX8986u+QCQ0HBXjFWNHnDohSf/oN/OOpge3khQ/Xv0nlPM3iuC6ZoFbOjzpxANFygEOYmRTjj9sYqBRAjo5jfRc2FVqbuDK7NKzZmw9cgw+XbV0DTSdAtdOf6HnaIMt6n8oTifJEALBKyVKag2OyEHSz8970HyAXp6RmBUcsCeOrWSYV/dZJLUWY74Wgo+JFEdzopnQGrczi2F2S5oVdOJv49rUgaU4gtoZBbXSrIhtb0Esl3I4h905+dQloufHH33haNwf+XgP2Bsm+zqpviY5lyeLNHI1sm8q6BUq96D5ZBky3ygyV9eFyiZrPb/XdqXiLtrRgnapkWoPuDWYN1BWkPO8a7L2+mwqb2UvlMNsCW5u3OqTBViazz7drAIlfcIVRivAanxsfKrjeq7Lr6YsTUh4kNAj0wMVs2CzWbBDjkK+MkGlkX4gzvjBuVC8Sp7QMoPbX76mmcVgL0Jm02dgj6JxQL/v1DxF/wInm73P9FCyZaGNH0S6iNeYcb4P8aYIdgXhWrW0HURshM+L35aQd/8C+R+xey1qp4gD82flncFtn3pX6y2FmjLwBMhiC/f4un7/NLu1M4UHk7skUVNK+KET3YUaSttjV+Pj6Y77pZnLO0bXkxojGxQRCOL3T/59DeJSM0KapA=----ATTACHMENT:----NTYyNDE3OTI2MDMwMDY4IDg5ODM0MTg3MDIyNTgyMyA4Mjk1ODczNzM5NDM1OTY=