/** * {@inheritdoc} */ protected function storeItemInCache(CacheItemInterface $item, $ttl) { $object = ['_id' => $item->getKey(), 'data' => serialize($item->get())]; if ($ttl) { $object['expiresAt'] = time() + $ttl; } $this->collection->updateOne(['_id' => $item->getKey()], ['$set' => $object], ['upsert' => true]); return true; }
/** * {@inheritdoc} */ public function save(ItemInterface $item) { $ttl = $item->getTtlInSecond(); $this->_tags = $item->getTags(); $item->setHit(true); $success = $this->cache_adapter->save($item->get(), $item->getKey(), $this->_tags, is_null($ttl) ? 0 : $ttl); $item->setHit($success); return $this; }
/** * {@inheritdoc} */ protected function storeItemInCache(CacheItemInterface $item, $ttl) { $key = $this->getHierarchyKey($item->getKey()); $data = serialize([true, $item->get(), $item->getTags()]); if ($ttl === null || $ttl === 0) { return $this->cache->set($key, $data); } return $this->cache->setex($key, $ttl, $data); }
/** * {@inheritdoc} */ 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); }
public function save(CacheItemInterface $item) { call_user_func(\Closure::bind(function () use($item) { $this->values[$item->getKey()] = $item->get(); $this->warmUp($this->values); $this->values = eval(substr(file_get_contents($this->file), 6)); }, $this, PhpArrayAdapter::class)); return true; }
/** * {@inheritdoc} */ protected function storeItemInCache(CacheItemInterface $item, $ttl) { if ($this->skipIfCli()) { return false; } if ($ttl < 0) { return false; } return apcu_store($item->getKey(), $item->get(), $ttl); }
/** * {@inheritdoc} */ protected function storeItemInCache(CacheItemInterface $item, $ttl) { if ($ttl < 0) { return false; } $ttl = null === $ttl ? 0 : $ttl / 60; if (null === ($value = $item->get())) { $value = self::NULL_VALUE; } $this->store->put($item->getKey(), $value, $ttl); return true; }
/** * {@inheritdoc} * @throws \InvalidArgumentException * @throws \League\Flysystem\FileNotFoundException * @throws \League\Flysystem\FileExistsException */ protected function storeItemInCache(CacheItemInterface $item, $ttl) { $file = $this->getFilePath($item->getKey()); if ($this->filesystem->has($file)) { $this->filesystem->delete($file); } $tags = []; if ($item instanceof TaggableItemInterface) { $tags = $item->getTags(); } return $this->filesystem->write($file, serialize([$ttl === null ? null : time() + $ttl, $item->get(), $tags])); }
/** * {@inheritdoc} */ protected function storeItemInCache(CacheItemInterface $item, $ttl) { if ($ttl === null) { $ttl = 0; } elseif ($ttl < 0) { return false; } elseif ($ttl > 86400 * 30) { // Any time higher than 30 days is interpreted as a unix timestamp date. // https://github.com/memcached/memcached/wiki/Programming#expiration $ttl = time() + $ttl; } $key = $this->getHierarchyKey($item->getKey()); return $this->cache->set($key, serialize([true, $item->get(), []]), $ttl); }
/** * {@inheritdoc} */ public function saveDeferred(CacheItemInterface $item) { if (null === $this->values) { $this->initialize(); } return !isset($this->values[$item->getKey()]) && $this->fallbackPool->saveDeferred($item); }
/** * @param CacheItemInterface $item * @return bool|void */ public function save(CacheItemInterface $item) { if (!$item instanceof CacheItem) { throw new InvalidArgumentException('The cache item must be an implementation of \\ByJG\\Cache\\Psr\\CacheItem'); } if ($item->getExpiresInSecs() < 1) { throw new InvalidArgumentException('Object has expired!'); } $this->_cacheEngine->set($item->getKey(), $item->get(), $item->getExpiresInSecs()); $this->addElementToBuffer($item); return true; }
/** * {@inheritdoc} */ public function saveDeferred(CacheItemInterface $item) { if (!$item instanceof CacheItem) { return false; } $this->deferred[$item->getKey()] = $item; return true; }
/** * {@inheritdoc} */ public function saveDeferred(CacheItemInterface $item) { if (!$item instanceof Item) { throw new InvalidArgumentException('MatthiasMullie\\Scrapbook\\Psr6\\Pool can only save MatthiasMullie\\Scrapbook\\Psr6\\Item objects'); } $this->deferred[$item->getKey()] = $item; // let's pretend that this actually comes from cache (we'll store it // there soon), unless if it's already expired (in which case it will // never reach cache...) $item->overrideIsHit(!$item->isExpired()); return true; }
public function save(CacheItemInterface $item) { $this->items_[$item->getKey()] = $item; return $this; }
/** * Persists a cache item immediately. * * @param CacheItemInterface $item * The cache item to save. * * @return bool * True if the item was successfully persisted. False if there was an error. * * @throws InvalidArgumentException */ public function save(CacheItemInterface $item) { $expirationTime = null; if ($item instanceof ExtractableCacheLifetimeInterface) { $expirationTime = $item->getCacheLifetime(); } return $this->cacheFrontend->save(serialize($item instanceof ExtractableCacheValueInterface ? $item->getCacheValue() : $item->get()), $this->prepareKey($item->getKey()), $this->tags, $expirationTime); }
/** * @param \Psr\Cache\CacheItemInterface $item * @return bool * @throws \InvalidArgumentException */ protected function driverDelete(CacheItemInterface $item) { /** * Check for Cross-Driver type confusion */ if ($item instanceof Item) { return xcache_unset($item->getKey()); } else { throw new \InvalidArgumentException('Cross-Driver type confusion detected'); } }
/** * @param \Psr\Cache\CacheItemInterface $item * @return mixed */ protected function driverRead(CacheItemInterface $item) { $val = $this->instance->get($item->getKey()); if ($val == false) { return null; } else { return $this->decode($val); } }
/** * กำหนดรายการแคชสำหรับบันทึกในภายหลัง * * @param CacheItemInterface $item * @return boolean false ถ้าไม่มีรายการในคิว */ public function saveDeferred(CacheItemInterface $item) { $this->deferred[$item->getKey()] = $item; return true; }
/** * @param \Psr\Cache\CacheItemInterface $item * @return bool * @throws \InvalidArgumentException */ protected function driverDelete(CacheItemInterface $item) { /** * Check for Cross-Driver type confusion */ if ($item instanceof Item) { $file_path = $this->getFilePath($item->getKey(), true); if (file_exists($file_path) && @unlink($file_path)) { return true; } else { return false; } } else { throw new \InvalidArgumentException('Cross-Driver type confusion detected'); } }
/** * {@inheritdoc} */ protected function storeItemInCache(CacheItemInterface $item, $ttl) { $key = $this->getHierarchyKey($item->getKey()); $this->cache[$key] = $item; if ($this->limit !== null) { // Remove the oldest value if (isset($this->keyMap[$this->currentPosition])) { unset($this->cache[$this->keyMap[$this->currentPosition]]); } // Add the new key to the current position $this->keyMap[$this->currentPosition] = $key; // Increase the current position $this->currentPosition = ($this->currentPosition + 1) % $this->limit; } return true; }
/** * {@inheritdoc} */ protected function storeItemInCache(CacheItemInterface $item, $ttl) { $data = serialize([true, $item->get(), []]); return $this->cache->set($item->getKey(), $data, 0, $ttl ?: 0); }
/** * {@inheritdoc} */ public function save(CacheItemInterface $item) { if (!$item instanceof CacheItem) { return false; } $key = $item->getKey(); $this->deferred[$key] = $item; $this->commit(); return !isset($this->deferred[$key]); }
/** * Persists a cache item immediately. * * @param CacheItemInterface $item * The cache item to save. * * @return static * The invoked object. */ public function save(CacheItemInterface $item) { return $this->getDriver()->save($item->getKey(), $item->get(), $item->getExpiration()); }
/** * Persists a cache item immediately. * * @param CacheItemInterface $item * The cache item to save. * * @return bool * True if the item was successfully persisted. False if there was an error. */ 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; }
public function saveDeferred(CacheItemInterface $item) { $key = $item->getKey(); $value = $this->getValueRepresentation($item->get()); $call = $this->timeCall(__FUNCTION__, [$item]); $call->arguments = ['<CacheItem>', $key, $value]; $this->addCall($call); return $call->result; }
/** * {@inheritdoc} */ public function save(CacheItemInterface $item) { $parts = $this->explodeKey($item->getKey()); $parentKey = ''; foreach ($parts as $part) { $parentKey .= $part; $parent = $this->cache->getItem($parentKey); $parent->set(null); $this->cache->save($parent); } return $this->cache->save($item); }
function it_commits_deferred_cache_items_only_onces(CacheItemInterface $cacheItem) { $cacheItem->get()->willReturn([1, 2, 3])->shouldBeCalledTimes(1); $cacheItem->getKey()->willReturn('key1')->shouldBeCalledTimes(1); $this->cacheFrontend->save(serialize([1, 2, 3]), 'prefix_key1', ['tag1', 'tag2'], null)->willReturn(true)->shouldBeCalledTimes(1); $this->saveDeferred($cacheItem)->shouldReturn(true); $this->commit()->shouldReturn(true); // This time nothing should happen $this->commit()->shouldReturn(true); }
/** * {@inheritdoc} */ public function save(CacheItemInterface $item) { $expiresInMinutes = null; if ($item instanceof CacheItem) { $expiresInMinutes = $item->getTTL(); } try { if (is_null($expiresInMinutes)) { $this->repository->forever($item->getKey(), serialize($item->get())); } else { $this->repository->put($item->getKey(), serialize($item->get()), $expiresInMinutes); } } catch (Exception $exception) { return false; } return true; }
public function getKey() { return $this->decorated->getKey(); }
/** * @param \Psr\Cache\CacheItemInterface $item * @return bool */ public function saveDeferred(\Psr\Cache\CacheItemInterface $item) { $this->cache[$item->getKey()] = $item; return true; }