Persists a cache item immediately.

@param CacheItem|CacheItemInterface $item
The cache item to save.

@return static The invoked object.
The invoked object.
182650
public function save(CacheItemInterface $item)
    {
        $item->setCacheItemPool($this);
        $key = [$this->getPoolName(), $item->getKey()];
        $key = $this->getDriver()->buildKey($key);

        $this->getDriver()->set($key, $this->phpSerialize($item->get()), $item->getExpiration());

        return $this;
    }
453330
protected function protectedSave(
        CacheItemInterface $item,
        $function = 'save'
    )/*# : bool */ {
        // write to both ?
        $func = $this->tester;
        $both = $func($item);

        // if $both is true, write to front
        $res1 = false;
        if ($both) {
            if ($this->front->$function($item)) {
                $res1 = true; // ok
            } else {
                $this->setError(
                    $this->front->getError(),
                    $this->front->getErrorCode()
                );
            }
        }

        // always write to backend
        $res2 = false;
        if ($this->back->$function($item)) {
            $res2 = true; // ok
        } else {
            $this->setError(
                $this->back->getError(),
                $this->back->getErrorCode()
            );
        }

        return $res1 || $res2 ? true : false;
    }
1231731
public function save(CacheItemInterface $item)
    {
        $lifetime = null;
        $expiresAt = null;
        if ($item instanceof CacheItem) {
            $expiresAt = $item->getExpirationDate();
        }

        if ($expiresAt instanceof \DateTimeInterface) {
            $lifetime = $expiresAt->getTimestamp() - (new \DateTime())->getTimestamp();
        }

        $this->backend->set($item->getKey(), serialize($item->get()), [], $lifetime);
        return true;
    }
1200790
public function set(CacheableInterface $item)
    {
        $this->provider->save($item->getHashKey(), $item->getDataForCache(), $item->getTtl());
    }
290061
public function addItem($item){
		$itemO=$this->getItemToAdd($item);
		$this->addContent($itemO);
		return $itemO;
	}
892053
public function save(CacheItemInterface $item)
    {
        $metadata = $item->getMetadata();
        $metadata[ 'data' ] = $item->get();

        return wincache_ucache_set($this->prefixKey . $item->getKey(), $metadata, $metadata[ 'ttl' ]);
    }
1183231
public function add($item)
    {
        foreach ($this->_requiredInterfaces as $interface) {
            if (!$item instanceof $interface) {
                throw new RuntimeException(
                    sprintf('Item "%s" should implement "%s" interface', get_class($item), $interface)
                );
            }
        }
        
        $this->_items[spl_object_hash($item)] = $item;
        return $this;
    }
1170278
public function clear_cache($item, $mode): self
  {
    $cache_name = $this->_cache_name($item, $mode);
    if ( $this->cache_has($cache_name) ){
      $this->cache_delete($cache_name);
    }
    return $this;
  }
594486
public function set(CacheableInterface $item)
    {
        $con = $this->getConnection();
        $con->set($item->getHashKey(), $item->getDataForCache());
        if (null != $item->getTtl()) {
            $con->expire($item->getHashKey(), $item->getTtl());
        }
    }
222981
public function save(CacheItemInterface $item)
    {
        if (! $item instanceof CacheItem) {
            throw new InvalidArgumentException('$item must be an instance of ' . CacheItem::class);
        }

        $this->validateKey($item->getKey());

        try {
            $options = false;
            $expiration = $item->getExpiration();

            // @todo I can't see any way to set the TTL on an individual item except by temporarily overwriting the
            //       option on the storage adapter. Not sure if all storage adapters will support this...
            if ($expiration instanceof DateTime) {
                $options = $this->storage->getOptions();
                $new = clone $options;
                $interval = $expiration->diff(new DateTime(), true);
                $new->setTtl($interval->format('%s'));
                $this->storage->setOptions($new);
            }

            $saved = $this->storage->setItem($item->getKey(), $item->get());

            if ($options) {
                $this->storage->setOptions($options);
            }

        } catch (Exception\InvalidArgumentException $e) {
            throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);

        } catch (Exception\ExceptionInterface $e) {
            throw new CacheException($e->getMessage(), $e->getCode(), $e);
        }

        return $saved;
    }
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);
        }
    }
227074
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->removeSource($this);
            }
            $this->item = $item;
            // add link on this item
            if ($item instanceof Item) {
                $this->item->addSource($this);
            }
        }

        return $this;
    }
335075
public function addItem(PricedItemInterface $item)
    {
        if ($this->hasItem($item)) {
            return $this;
        }

        foreach ($this->items as $existingItem) {
            if ($item->equals($existingItem)) {
                $existingItem->merge($item, false);

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

                return $this;
            }
        }

        $item->setContainer($this);
        $this->items->add($item);

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

        return $this;
    }
196173
public function save(CacheItemInterface $item)
    {
        $key = $item->getKey();

        $this->validateKey($key);

        $this->data[$key] = $item;

        return true;
    }
1162944
public function set(CacheableInterface $item)
    {
        $targetFile = $this->getTargetFile($item->getHashKey());

        $cacheData = serialize($item->getDataForCache());

        if (!file_put_contents($targetFile, sprintf('%s%s;', self::STR_PREFIX, $cacheData))) {
            throw new \RuntimeException(
                sprintf(
                    'Unable to write cache file %s with data : %s',
                    $targetFile,
                    $cacheData
                )
            );
        }
    }
898948
public static function delete($item)
	{
		if (isset(static::$itemcache[$item]))
		{
			unset(static::$itemcache[$item]);
		}
		return \Arr::delete(static::$items, $item);
	}
1017465
public function writeItem(array $item)
    {
        //convert
        $objectOrItem = $this->convert($item);

        //write
        $this->write($objectOrItem);

        return $this;
    }