Metaphore\Cache::onNoStaleCache PHP Method

onNoStaleCache() public method

public onNoStaleCache ( callable $onNoStaleCacheCallable )
$onNoStaleCacheCallable callable
    public function onNoStaleCache(callable $onNoStaleCacheCallable)
    {
        $this->onNoStaleCacheCallable = $onNoStaleCacheCallable;
    }

Usage Example

Exemplo n.º 1
0
 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);
 }