本文整理匯總了PHP中Psr\Cache\CacheItemInterface::getTags方法的典型用法代碼示例。如果您正苦於以下問題:PHP CacheItemInterface::getTags方法的具體用法?PHP CacheItemInterface::getTags怎麽用?PHP CacheItemInterface::getTags使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Psr\Cache\CacheItemInterface
的用法示例。
在下文中一共展示了CacheItemInterface::getTags方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: storeItemInCache
/**
* {@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);
}
示例2: save
/**
* {@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;
}
示例3: 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]));
}
示例4: driverWrite
/**
* @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');
}
}
示例5: storeItemInCache
/**
* {@inheritdoc}
*/
protected function storeItemInCache(CacheItemInterface $item, $ttl)
{
$tags = [];
if ($item instanceof TaggableItemInterface) {
$tags = $item->getTags();
}
$data = serialize([$ttl === null ? null : time() + $ttl, $item->get(), $tags]);
$file = $this->getFilePath($item->getKey());
if ($this->filesystem->has($file)) {
// Update file if it exists
return $this->filesystem->update($file, $data);
}
try {
return $this->filesystem->write($file, $data);
} catch (FileExistsException $e) {
// To handle issues when/if race conditions occurs, we try to update here.
return $this->filesystem->update($file, $data);
}
}
示例6: storeItemInCache
/**
* {@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);
}