public function testCallableCanReturnDifferentValueIfNotStaleContentAvailableToServe() { $cache = new Cache(new MockStore()); $customValue = 'custom_value'; $cache->onNoStaleCache(function (NoStaleCacheEvent $event) use($customValue) { $event->setResult($customValue); }); $key = 'lamela'; $value = 'Tottenham Rabona'; $ttl = 30; // simulate lock (other process generating content) $cache->getLockManager()->acquire($key, 30); $result = $cache->cache($key, $this->createFunc($value), $ttl); $this->assertSame($customValue, $result); }
/** * @see CacheAdapterInterface::cache() */ public function cache($key, callable $callable, $ttl) { return $this->backend->cache($this->prefix . $key, $callable, $ttl); }