Persisting our data in the cache, uniquely referenced by a key with an optional expiration TTL time.

@param CacheItemInterface $item The cache item to store.

@return static Return self to support chaining
326660
public function save(CacheItemInterface $item)
    {
        $key = $item->getKey();
        $value = $item->get();

        $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 = $this->write(
            $fileName,
            $value,
            ($this->options['file_locking'] ? LOCK_EX : null)
        );

        return $success;
    }
72686
public function remember($lifetime = null)
    {
        $this->shouldCache = true;

        // Make sure something other than the default value (null) is given.
        // Then resolve the DateTime instance from the given value.
        if ($lifetime !== null) {
            $this->cacheLifetime = $this->resolveCacheLifetime($lifetime);
        }

        return $this;
    }
1133747
protected function persist(Item $item)
    {
        $this->em->persist($item);
        foreach ($item->getNames() as $name) {
            $this->em->persist($name);
        }
        foreach ($item->getSources() as $source) {
            $this->em->persist($source);
        }
    }
1265533
public function set(CacheItem $item): self
    {
        $driver = $this->getDriver();
        $driver->set($item->key, $item->value, $item->ttl);
        if ($this->hasEventListeners('itemSet')) {
            $this->dispatchEvent('itemSet', new \BearFramework\App\Cache\ItemSetEventDetails(clone($item)));
        }
        if ($this->hasEventListeners('itemChange')) {
            $this->dispatchEvent('itemChange', new \BearFramework\App\Cache\ItemChangeEventDetails($item->key));
        }
        return $this;
    }
844802
public function isCached(CacheItemInterface $item = null)
    {
        if (!$item) {
            $key = $this->getCurrentKey();
            $item = $this->getItemStorage()->get($key);
        }

        return $item ? true : false;
    }
743155
public function set(CacheableInterface $item)
    {
        parent::set($item);
        $this->adapter->set($item);
    }
354185
public function removeItem(PricedItemInterface $item)
    {
        if ($this->hasItem($item)) {
            $item->setContainer(null);
            $this->items->removeElement($item);

            $this->itemsTotal = null;
            $this->total = null;
        }

        return $this;
    }
596084
public function saveItem($key, $value, $ttl = null)
    {
        if (!$this->hasItem($key)) {
            $cacheFile = __cache_path().md5($key);
            $fileHandling = new FileHandling();
            $fileHandling->open($cacheFile, 'writeAppend')->write(json_encode([
                'start' => time(),
                'ttl'   => ($ttl !== null) ? (int) $ttl : $this->ttl,
                'value' => $value,
            ]));
            $fileHandling->close();
        }

        return $this;
    }
1121168
public function set($key, $value, $ttl = null)
    {
        $item = new Item($key, $value);
        if ($ttl !== null) {
            $item->expiresAfter($ttl);
        }
        return $this->save($item);
    }
922274
protected final function poolDeleteItem(CacheItemInterface $item): bool
    {
         return is_file($this->includePath . $item->getKey())
             && unlink($this->includePath . $item->getKey());
    }
804641
public function remove(CacheableInterface $item)
    {
        $targetFile = $this->getTargetFile($item->getHashKey());
        if (file_exists($targetFile) && !unlink($targetFile)) {
            throw new \RuntimeException(
                sprintf('Unable to delete %s cache file', $targetFile)
            );
        }
    }
583642
public function saveDeferred($key, $item, $ttl = null)
    {
        $this->queue[$key]['data'] = $item;
        if (null != $ttl) {
            $this->queue[$key]['ttl'] = $ttl;
        }
    }
792370
public function saveItem(StorableInterface $item)
    {
        if ($this->tableExists() === false) {
            /** @todo Optionnally turn off for some models */
            $this->createTable();
        }

        if ($item !== null) {
            $this->setModel($item);
        }
        $model  = $this->model();
        $table  = $this->table();
        $struct = array_keys($this->tableStructure());
        $fields = $this->getModelFields($model);

        $keys   = [];
        $values = [];
        $binds  = [];
        $types  = [];
        foreach ($fields as $field) {
            $key = $field->ident();
            if (in_array($key, $struct)) {
                $keys[]      = '`'.$key.'`';
                $values[]    = ':'.$key.'';
                $binds[$key] = $field->val();
                $types[$key] = $field->sqlPdoType();
            }
        }

        $query = '
            INSERT
                INTO
            `'.$table.'`
                ('.implode(', ', $keys).')
            VALUES
                ('.implode(', ', $values).')';

        $result = $this->dbQuery($query, $binds, $types);

        if ($result === false) {
            throw new PDOException('Could not save item.');
        } else {
            if ($model->id()) {
                return $model->id();
            } else {
                return $this->db()->lastInsertId();
            }
        }
    }
1117063
public function save(CacheItemInterface $item)
    {
        $metadata = $item->getMetadata();
        $metadata[ 'data' ] = $item->get();
        $metadata = serialize($metadata);

        $path = $this->path . $this->prefixKey . $item->getKey() . '.cache';

        if ( ! $fp = @fopen($path, 'wb')) {
            return false;
        }

        flock($fp, LOCK_EX);

        for ($result = $written = 0, $length = strlen($metadata); $written < $length; $written += $result) {
            if (($result = fwrite($fp, substr($metadata, $written))) === false) {
                break;
            }
        }

        flock($fp, LOCK_UN);
        fclose($fp);

        return (bool)is_int($result);
    }
1061267
public function save(CacheItemInterface $item)
    {
        $key = $item->getKey();

        $this->validateKey($key);

        $data = serialize($item);

        $result = file_put_contents($this->getPath($key), $data);

        if ($result === false) {
            return false;
        }

        return true;
    }
442062
def store(self, key, expiry, data):
        
        self.cache.set(key, (expiry, data), self.cache_ttl)

        if getattr(settings, 'CACHEBACK_VERIFY_CACHE_WRITE', True):
            # We verify that the item was cached correctly.  This is to avoid a
            # Memcache problem where some values aren't cached correctly
            # without warning.
            __, cached_data = self.cache.get(key, (None, None))
            if data is not None and cached_data is None:
                raise RuntimeError(
                    "Unable to save data of type %s to cache" % (
                        type(data)))
661518
public function setItem(Item $item = null)
    {
        if ($this->item !== $item) {
            // romove link on this item for old item
            if ($this->item instanceof Item) {
                $tmp = $this->item;
                $this->item = null;
                $tmp->removeImage($this);
            }
            $this->item = $item;
            // add link on this item
            if ($item instanceof Item) {
                $this->item->addImage($this);
            }
        }

        return $this;
    }