public function save($key, CacheEntry $data)
{
if ($this->lastItem && $this->lastItem->getKey() == $key) {
$item = $this->lastItem;
} else {
$item = $this->cachePool->getItem($key);
}
$this->lastItem = null;
$item->set($data);
$ttl = $data->getTTL();
if ($ttl === 0) {
// No expiration
$item->expiresAfter(null);
} else {
$item->expiresAfter($ttl);
}
return $this->cachePool->save($item);
}