本文整理汇总了PHP中Psr\Cache\CacheItemInterface类的典型用法代码示例。如果您正苦于以下问题:PHP CacheItemInterface类的具体用法?PHP CacheItemInterface怎么用?PHP CacheItemInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CacheItemInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: storeItemInCache
protected function storeItemInCache($key, CacheItemInterface $item, $ttl)
{
if ($ttl < 0) {
return false;
}
return apc_store($key, $item->get(), $ttl);
}
示例2: finalizeItem
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.');
}
示例3: storeItemInCache
protected function storeItemInCache($key, CacheItemInterface $item, $ttl)
{
if ($ttl === null) {
$ttl = 0;
}
return $this->cache->save($key, serialize($item->get()), $ttl);
}
示例4: proxySave
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.');
}
示例5: storeItemInCache
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()]));
}
示例6: storeItemInCache
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);
}
示例7: storeItemInCache
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;
}
示例8: storeItemInCache
/**
* {@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;
}
示例9: save
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;
}
示例10: storeItemInCache
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);
}
示例11: save
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;
}
示例12: storeItemInCache
/**
* {@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);
}
示例13: storeItemInCache
/**
* {@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]));
}
示例14: storeItemInCache
/**
* {@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;
}
示例15: storeItemInCache
/**
* {@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);
}