Esempio n. 1
0
 protected function storeItemInCache($key, CacheItemInterface $item, $ttl)
 {
     if ($ttl < 0) {
         return false;
     }
     return apc_store($key, $item->get(), $ttl);
 }
 private function finalizeItem(CacheItemInterface $item)
 {
     if ($item instanceof ItemDecorator) {
         return $item->finalize();
     }
     throw new InvalidArgumentException('The provided cache item cannot' . ' be saved, as it did not originate from this cache.');
 }
 protected function storeItemInCache($key, CacheItemInterface $item, $ttl)
 {
     if ($ttl === null) {
         $ttl = 0;
     }
     return $this->cache->save($key, serialize($item->get()), $ttl);
 }
 private function proxySave(CacheItemInterface $item, $deferred = false)
 {
     if ($item instanceof ItemDecorator) {
         return $this->decorated->{$deferred ? 'saveDeferred' : 'save'}($item->getDecorated());
     }
     throw new InvalidArgumentException('The provided cache item cannot' . ' be saved, as it did not originate from this cache.');
 }
 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);
 }
Esempio n. 7
0
 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;
 }
Esempio n. 8
0
 /**
  * {@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;
 }
Esempio n. 9
0
 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;
 }
Esempio n. 10
0
 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);
 }
Esempio n. 11
0
 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;
 }
Esempio n. 12
0
 /**
  * {@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}
  * @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 < 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;
 }
Esempio n. 15
0
 /**
  * {@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 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);
 }
 /**
  * @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);
 }
Esempio n. 18
0
 /**
  * {@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;
 }
Esempio n. 19
0
 /**
  * @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');
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function storeItemInCache(CacheItemInterface $item, $ttl)
 {
     if ($ttl === null) {
         $ttl = 0;
     }
     $tags = [];
     if ($item instanceof TaggableItemInterface) {
         $tags = $item->getTags();
     }
     $data = serialize([true, $item->get(), $tags]);
     return $this->cache->save($item->getKey(), $data, $ttl);
 }
Esempio n. 21
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();
 }
Esempio n. 22
0
 /**
  * @param ResponseInterface  $response
  * @param CacheItemInterface $item
  * @param array|null         $data
  *
  * @throws \RuntimeException
  *
  * @return array
  */
 protected function handleSuccessfulResponse(ResponseInterface $response, CacheItemInterface $item = null)
 {
     switch ((int) $response->getStatusCode()) {
         case 200:
             $data = json_decode($response->getBody(), true);
             if ($item !== null && $response->hasHeader('Last-Modified') === true) {
                 $item->set(['modified' => $response->getHeader('Last-Modified'), 'json' => $data]);
                 $this->cache->save($item);
             }
             return $data;
         case 304:
             return $item->get()['json'];
         default:
             throw new \RuntimeException('No support added for HTTP Status Code ' . $response->getStatusCode());
     }
 }
Esempio n. 23
0
 /**
  * Minify the data & write it to a CacheItemInterface object.
  *
  * @param  CacheItemInterface $item Cache item to write the data to.
  * @return CacheItemInterface       Cache item with the minifier data.
  */
 public function cache(CacheItemInterface $item)
 {
     $content = $this->execute();
     $item->set($content);
     return $item;
 }
Esempio n. 24
0
 /**
  * {@inheritdoc}
  */
 public function saveDeferred(CacheItemInterface $item)
 {
     if (null === $this->values) {
         $this->initialize();
     }
     return !isset($this->values[$item->getKey()]) && $this->fallbackPool->saveDeferred($item);
 }
Esempio n. 25
0
 /**
  * กำหนดรายการแคชสำหรับบันทึกในภายหลัง
  *
  * @param CacheItemInterface $item
  * @return boolean false ถ้าไม่มีรายการในคิว
  */
 public function saveDeferred(CacheItemInterface $item)
 {
     $this->deferred[$item->getKey()] = $item;
     return true;
 }
Esempio n. 26
0
 /**
  * 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;
         }
     }
 }
 /**
  * A TagId is retrieved from cache using the TagKey.
  *
  * @param \Psr\Cache\CacheItemPoolInterface $storage
  * @param CacheItemInterface                $item
  *
  * @return string
  */
 private function generateNewTagId(CacheItemInterface $item)
 {
     $value = str_replace('.', '', uniqid('', true));
     $item->set($value);
     $item->expiresAfter(null);
     $this->save($item);
     // Save to temporary tag store
     $this->tags[$item->getKey()] = $value;
     return $value;
 }
Esempio n. 28
0
 /**
  * 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->isHit()) {
         return false;
     }
     return $this->local->save($item) && $this->remote->save($item);
 }
Esempio n. 29
0
 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;
 }
 /**
  * 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;
 }