/** * Persisting our data in the cache, uniquely referenced by a key with an optional expiration TTL time. * * @param CacheItem $item The cache item to store. * @param int|\DateInterval|\DateTime $ttl The Time To Live of an item. * * @return static Return self to support chaining */ public function setItem($item, $ttl = null) { $key = $item->getKey(); $value = $item->getValue(); $fileName = $this->fetchStreamUri($key); $filePath = pathinfo($fileName, PATHINFO_DIRNAME); if (!is_dir($filePath)) { mkdir($filePath, 0770, true); } if ($this->denyAccess) { $value = $this->options['deny_code'] . $value; } $success = (bool) file_put_contents($fileName, $value, $this->options['file_locking'] ? LOCK_EX : null); return $success; }