【发布时间】:2018-01-14 14:08:40
【问题描述】:
我尝试将值保存到自定义 Magento 2 缓存中。
这是我在 Model/Cache/Type.php 下自定义缓存的代码
class Type extends \Magento\Framework\Cache\Frontend\Decorator\TagScope
{
const TYPE_IDENTIFIER = 'cache_tag';
const CACHE_TAG = 'CACHE_TAG';
/**
* @param \Magento\Framework\App\Cache\Type\FrontendPool $cacheFrontendPool
*/
public function __construct(\Magento\Framework\App\Cache\Type\FrontendPool $cacheFrontendPool)
{
parent::__construct($cacheFrontendPool->get(self::TYPE_IDENTIFIER), self::CACHE_TAG);
}
}
这是 etc/cache.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Cache/etc/cache.xsd">
<type name="xxx_cache" translate="label,description" instance="XXX\XXX\Model\Cache\Type">
<label>XXX Cache type</label>
<description>XXX cache description.</description>
</type>
现在我尝试将数据保存并加载到此自定义缓存中:
$this->cache->save(serialize("Data"), md5("Identifier"));
$data = $this->cache->load(md5("Identifier"));
$this->logger->debug("Data: " . print_r(unserialize($data)), true);
这是记录器输出:[2017-08-07 09:37:08] main.DEBUG: Data: {"is_exception":false} []
为什么我没有得到字符串“Data”?
【问题讨论】: