Metaphore\Cache::setResult PHP Method

setResult() public method

Sets result. Does not use anti-dogpile-effect mechanism. Use cache() instead for this.
public setResult ( $key, $result, $ttl )
    public function setResult($key, $result, $ttl)
    {
        if (!$ttl instanceof Ttl) {
            $ttl = new Ttl($ttl);
        }
        $expirationTimestamp = time() + $ttl->getTtl();
        $value = new Value($result, $expirationTimestamp);
        $this->valueStore->set($key, $value, $ttl->getRealTtl());
    }

Usage Example

Exemplo n.º 1
0
 public function testGetReturnsResultEvenIfNoMetaphoreValueObjectStored()
 {
     $cache = new Cache(new MockStore());
     $key = 'dimaria7';
     $value = 'Man Utd, not Real';
     $cache->setResult($key, $value, new Ttl(30));
     $result = $cache->getValue($key);
     $this->assertTrue($result instanceof \Metaphore\Value);
     $this->assertSame($value, $result->getResult());
 }