3 namespace Friendica\Core\Cache;
5 use Friendica\Core\System;
6 use Friendica\Util\Profiler;
9 * This class wraps cache driver so they can get profiled - in case the profiler is enabled
11 * It is using the decorator pattern (@see
13 class ProfilerCache implements ICache, IMemoryCache
16 * @var ICache The original cache driver
21 * @var Profiler The profiler of Friendica
25 public function __construct(ICache $cache, Profiler $profiler)
27 $this->cache = $cache;
28 $this->profiler = $profiler;
34 public function getAllKeys($prefix = null)
36 $time = microtime(true);
38 $return = $this->cache->getAllKeys($prefix);
40 $this->profiler->saveTimestamp($time, 'cache', System::callstack());
48 public function get($key)
50 $time = microtime(true);
52 $return = $this->cache->get($key);
54 $this->profiler->saveTimestamp($time, 'cache', System::callstack());
62 public function set($key, $value, $ttl = Duration::FIVE_MINUTES)
64 $time = microtime(true);
66 $return = $this->cache->set($key, $value, $ttl);
68 $this->profiler->saveTimestamp($time, 'cache', System::callstack());
76 public function delete($key)
78 $time = microtime(true);
80 $return = $this->cache->delete($key);
82 $this->profiler->saveTimestamp($time, 'cache', System::callstack());
90 public function clear($outdated = true)
92 $time = microtime(true);
94 $return = $this->cache->clear($outdated);
96 $this->profiler->saveTimestamp($time, 'cache', System::callstack());
104 public function add($key, $value, $ttl = Duration::FIVE_MINUTES)
106 if ($this->cache instanceof IMemoryCache) {
107 $time = microtime(true);
109 $return = $this->cache->add($key, $value, $ttl);
111 $this->profiler->saveTimestamp($time, 'cache', System::callstack());
122 public function compareSet($key, $oldValue, $newValue, $ttl = Duration::FIVE_MINUTES)
124 if ($this->cache instanceof IMemoryCache) {
125 $time = microtime(true);
127 $return = $this->cache->compareSet($key, $oldValue, $newValue, $ttl);
129 $this->profiler->saveTimestamp($time, 'cache', System::callstack());
140 public function compareDelete($key, $value)
142 if ($this->cache instanceof IMemoryCache) {
143 $time = microtime(true);
145 $return = $this->cache->compareDelete($key, $value);
147 $this->profiler->saveTimestamp($time, 'cache', System::callstack());
158 public function GetName()
160 return $this->cache->getName() . ' (with profiler)';