/** * @covers Xoops\Core\Cache\Access::cacheRead * @covers Xoops\Core\Cache\Access::read * @covers Xoops\Core\Cache\Access::delete */ public function testCacheRead() { $regenFunction = function ($args) { $vars = func_get_args(); return $vars[0]; }; $key = 'testCacheRead'; $value = 'fred'; $ret = $this->object->delete($key); $ret = $this->object->cacheRead($key, $regenFunction, 60, $value); $this->assertEquals($ret, $value); // this should return cached value, not current regenFunction result $ret = $this->object->cacheRead($key, $regenFunction, 60, 'not' . $value); $this->assertEquals($ret, $value); $ret = $this->object->read($key); $this->assertEquals($ret, $value); }
/** * cache block wrapper * * If the cache read for $key is a miss, call the $regenFunction to update it. * With the PRECOMPUTE strategy, it will trigger a miss on a read on one caller * before the cache expires, so it will be done in advance. * * @param string|string[] $cacheKey Identifier for the cache item * @param callable $regenFunction function to generate cached content * @param int|DateTime|null $ttl time to live, number ofseconds as integer, * DateTime to expire at a specific time, * or null for default * @param mixed ...$args variable argument list for $regenFunction * * @return mixed */ public function cacheRead($cacheKey, $regenFunction, $ttl = null, $args = null) { return $this->cache->cacheRead($this->prefix($cacheKey), $regenFunction, $ttl, $args); }