Path: blob/master/src/infrastructure/cache/PhutilKeyValueCacheProfiler.php
12241 views
<?php12final class PhutilKeyValueCacheProfiler extends PhutilKeyValueCacheProxy {34private $profiler;5private $name;67public function setName($name) {8$this->name = $name;9return $this;10}1112public function getName() {13return $this->name;14}1516/**17* Set a profiler for cache operations.18*19* @param PhutilServiceProfiler Service profiler.20* @return this21* @task kvimpl22*/23public function setProfiler(PhutilServiceProfiler $profiler) {24$this->profiler = $profiler;25return $this;26}272829/**30* Get the current profiler.31*32* @return PhutilServiceProfiler|null Profiler, or null if none is set.33* @task kvimpl34*/35public function getProfiler() {36return $this->profiler;37}383940public function getKeys(array $keys) {41$call_id = null;42if ($this->getProfiler()) {43$call_id = $this->getProfiler()->beginServiceCall(44array(45'type' => 'kvcache-get',46'name' => $this->getName(),47'keys' => $keys,48));49}5051$results = parent::getKeys($keys);5253if ($call_id !== null) {54$this->getProfiler()->endServiceCall(55$call_id,56array(57'hits' => array_keys($results),58));59}6061return $results;62}636465public function setKeys(array $keys, $ttl = null) {66$call_id = null;67if ($this->getProfiler()) {68$call_id = $this->getProfiler()->beginServiceCall(69array(70'type' => 'kvcache-set',71'name' => $this->getName(),72'keys' => array_keys($keys),73'ttl' => $ttl,74));75}7677$result = parent::setKeys($keys, $ttl);7879if ($call_id !== null) {80$this->getProfiler()->endServiceCall($call_id, array());81}8283return $result;84}858687public function deleteKeys(array $keys) {88$call_id = null;89if ($this->getProfiler()) {90$call_id = $this->getProfiler()->beginServiceCall(91array(92'type' => 'kvcache-del',93'name' => $this->getName(),94'keys' => $keys,95));96}9798$result = parent::deleteKeys($keys);99100if ($call_id !== null) {101$this->getProfiler()->endServiceCall($call_id, array());102}103104return $result;105}106107}108109110