Cache\Adapter\PHPArray\ArrayCachePool::save PHP Method

save() public method

public save ( Psr\Cache\CacheItemInterface $item )
$item Psr\Cache\CacheItemInterface
    public function save(CacheItemInterface $item)
    {
        if ($item instanceof TaggableItemInterface) {
            $this->saveTags($item);
        }
        return parent::save($item);
    }

Usage Example

 public function testLimit()
 {
     $pool = new ArrayCachePool(2);
     $item = $pool->getItem('key1')->set('value1');
     $pool->save($item);
     $item = $pool->getItem('key2')->set('value2');
     $pool->save($item);
     // Both items should be in the pool, nothing strange yet
     $this->assertTrue($pool->hasItem('key1'));
     $this->assertTrue($pool->hasItem('key2'));
     $item = $pool->getItem('key3')->set('value3');
     $pool->save($item);
     // First item should be dropped
     $this->assertFalse($pool->hasItem('key1'));
     $this->assertTrue($pool->hasItem('key2'));
     $this->assertTrue($pool->hasItem('key3'));
     $this->assertFalse($pool->getItem('key1')->isHit());
     $this->assertTrue($pool->getItem('key2')->isHit());
     $this->assertTrue($pool->getItem('key3')->isHit());
     $item = $pool->getItem('key4')->set('value4');
     $pool->save($item);
     // Only the last two items should be in place
     $this->assertFalse($pool->hasItem('key1'));
     $this->assertFalse($pool->hasItem('key2'));
     $this->assertTrue($pool->hasItem('key3'));
     $this->assertTrue($pool->hasItem('key4'));
 }