protected function storeItemInCache($key, CacheItemInterface $item, $ttl) { if ($ttl < 0) { return false; } return apc_store($key, $item->get(), $ttl); }
protected function storeItemInCache($key, CacheItemInterface $item, $ttl) { if ($ttl === null) { $ttl = 0; } return $this->cache->save($key, serialize($item->get()), $ttl); }
protected function storeItemInCache($key, CacheItemInterface $item, $ttl) { $file = $this->getFilePath($key); if ($this->filesystem->has($file)) { $this->filesystem->delete($file); } return $this->filesystem->write($file, serialize([$ttl === null ? null : time() + $ttl, $item->get()])); }
protected function storeItemInCache($key, CacheItemInterface $item, $ttl) { if ($ttl === null) { $ttl = 0; } $key = $this->getHierarchyKey($key); return $this->cache->set($key, serialize([true, $item->get()]), $ttl); }
/** * {@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; }
protected function storeItemInCache($key, CacheItemInterface $item, $ttl) { $object = ['_id' => $key, 'data' => serialize($item->get())]; if ($ttl) { $object['expiresAt'] = new UTCDateTime((time() + $ttl) * 1000); } $this->collection->updateOne(['_id' => $key], ['$set' => $object], ['upsert' => true]); return true; }
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; }
protected function storeItemInCache($key, CacheItemInterface $item, $ttl) { $key = $this->getHierarchyKey($key); $data = serialize([true, $item->get()]); if ($ttl === null) { return $this->cache->set($key, $data); } return $this->cache->setex($key, $ttl, $data); }
/** * {@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; }
public function save(CacheItemInterface $item) { $itemClone = clone $item; $itemClone->set(sprintf('<DATA:%s', gettype($item->get()))); $call = $this->timeCall(__FUNCTION__, [$item]); $call->arguments = ['<CacheItem>', $itemClone]; $this->calls[] = $call; return $call->result; }
/** * {@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); }
/** * @return bool */ private function tryToSetTokenFromDecorated() { if (empty($this->token)) { try { $this->token = Token::fromSealed($this->password, $this->decorated->get()); } catch (Throwable $t) { } } return isset($this->token); }
/** * {@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} */ 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); }
/** * @param \Psr\Cache\CacheItemInterface $item * @return mixed * @throws \InvalidArgumentException */ protected function driverWrite(CacheItemInterface $item) { /** * Check for Cross-Driver type confusion */ if ($item instanceof Item) { try { $result = (array) $this->getCollection()->update(['_id' => $item->getKey()], ['$set' => [self::DRIVER_EDATE_WRAPPER_INDEX => $item->getTtl() > 0 ? new MongoDate(time() + $item->getTtl()) : new MongoDate(time()), self::DRIVER_DATA_WRAPPER_INDEX => new MongoBinData($this->encode($item->get()), MongoBinData::BYTE_ARRAY), self::DRIVER_TAGS_WRAPPER_INDEX => new MongoBinData($this->encode($item->getTags()), MongoBinData::BYTE_ARRAY)]], ['upsert' => true, 'multiple' => false]); } catch (MongoCursorException $e) { return false; } return isset($result['ok']) ? $result['ok'] == 1 : true; } else { throw new \InvalidArgumentException('Cross-Driver type confusion detected'); } }
/** * {@inheritdoc} */ public function save(CacheItemInterface $item) { $storageKey = $this->createKey($item->getKey()); $ttl = $this->ttl; if ($item instanceof CacheItem) { $expiration = $item->getExpiration()->getTimestamp(); $time = time(); if ($expiration > $time) { $ttl = $expiration - $time; } } return $this->setDataToStorage($storageKey, $item->get(), $ttl); }
/** * @param string $key * @param CacheItemInterface $item * @param int|null $ttl * @return bool */ protected function storeItemInCache($key, CacheItemInterface $item, $ttl) { if ($ttl === null) { $ttl = $this->configuration->getTimeToLive(); } // always save the key in record $policy = [\Aerospike::OPT_POLICY_KEY => \Aerospike::POLICY_KEY_SEND]; $transformedKey = $this->transformKey($key); $bins = [self::AEROSPIKE_BIN => $item->get()]; $status = $this->cache->put($transformedKey, $bins, $ttl, $policy); if ($status == \Aerospike::OK) { return true; } return false; }
/** * Get the ETag from the cached response. * * @param CacheItemInterface $cacheItem * * @return string|null */ private function getETag(CacheItemInterface $cacheItem) { $data = $cacheItem->get(); // The isset() is to be removed in 2.0. if (!isset($data['etag'])) { return; } if (!is_array($data['etag'])) { return $data['etag']; } foreach ($data['etag'] as $etag) { if (!empty($etag)) { return $etag; } } }
protected function storeItemInCache($key, CacheItemInterface $item, $ttl) { $data = serialize([true, $item->get()]); return $this->cache->set($key, $data, 0, $ttl ?: 0); }
/** * {@inheritdoc} */ protected function storeItemInCache(CacheItemInterface $item, $ttl) { if ($ttl < 0) { return false; } $key = $this->getHierarchyKey($item->getKey()); $data = serialize([true, $item->get(), $item->getTags()]); if ($ttl === null || $ttl === 0) { return 'OK' === $this->cache->set($key, $data)->getPayload(); } return 'OK' === $this->cache->setex($key, $ttl, $data)->getPayload(); }
/** * {@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; }
/** * 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) { if (!$item instanceof Item) { throw new InvalidArgumentException('MatthiasMullie\\Scrapbook\\Psr6\\Pool can only save MatthiasMullie\\Scrapbook\\Psr6\\Item objects'); } if (!$item->hasChanged()) { /* * If the item didn't change, we don't have to re-save it. We do, * however, need to check if the item actually holds a value: if it * does, it should be considered "saved" (even though nothing has * changed, the value for this key is in cache) and if it doesn't, * well then nothing is in cache. */ return $item->get() !== null; } $expire = $item->getExpiration(); return $this->store->set($item->getKey(), $item->get(), $expire); }
/** * @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; }
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); }
/** * 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); }
protected function storeItemInCache($key, CacheItemInterface $item, $ttl) { return apcu_store($key, $item->get(), $ttl); }
/** * @param string $key * @param CacheItemInterface $item * @param int|null $ttl * @return bool */ protected function storeItemInCache($key, CacheItemInterface $item, $ttl) { if ($ttl === null) { $ttl = $this->configuration->getTimeToLive(); } return $this->cache->set($key, serialize($item->get()), $ttl); }
/** * 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()); }