protected function storeItemInCache(CacheItemInterface $item, $ttl)
{
$tags = [];
if ($item instanceof TaggableItemInterface) {
$tags = $item->getTags();
}
$data = serialize([$ttl === null ? null : time() + $ttl, $item->get(), $tags]);
$file = $this->getFilePath($item->getKey());
if ($this->filesystem->has($file)) {
// Update file if it exists
return $this->filesystem->update($file, $data);
}
try {
return $this->filesystem->write($file, $data);
} catch (FileExistsException $e) {
// To handle issues when/if race conditions occurs, we try to update here.
return $this->filesystem->update($file, $data);
}
}