Stash\Item::lock PHP Method

lock() public method

public lock ( $ttl = null )
    public function lock($ttl = null)
    {
        if ($this->isDisabled()) {
            return true;
        }
        if (!isset($this->key)) {
            return false;
        }
        $this->stampedeRunning = true;
        $expiration = isset($ttl) && is_numeric($ttl) ? (int) $ttl : $this->defaults['stampede_ttl'];
        $spkey = $this->key;
        $spkey[0] = 'sp';
        return $this->driver->storeData($spkey, true, time() + $expiration);
    }

Usage Example

 private function assertDisabledStash(Item $stash)
 {
     $this->assertFalse($stash->set('true'), 'storeData returns false for disabled cache');
     $this->assertNull($stash->get(), 'getData returns null for disabled cache');
     $this->assertFalse($stash->clear(), 'clear returns false for disabled cache');
     $this->assertTrue($stash->isMiss(), 'isMiss returns true for disabled cache');
     $this->assertFalse($stash->extendCache(), 'extendCache returns false for disabled cache');
     $this->assertTrue($stash->lock(100), 'lock returns true for disabled cache');
 }