具有管理员开关的Magento自定义缓存



我正在编写一个使用某种自定义缓存机制的模块,我希望我的缓存与核心Magento缓存一起从管理区域中清除。

我还想检查是否仅为我的模块启用了缓存,然后基于此选择是否进行缓存。

我相信这是可能的,但不知道如何。

Magento使这变得非常容易,基本上只是模块全局配置中的几行代码...

<global>
    <!-- Other global config -->
    <cache>
        <types>
            <namespace_module module="namespace_module" translate="label description">
                <label>Your modules cache label</label>
                <description>Description of your modules cache</description>
                <tags>YOUR_MODULES_CACHE_TAGS</tags>
            </namespace_module>
        </types>
    </cache>
    <!-- Other global config -->
</global>

检查缓存是否处于活动状态的逻辑如下...

$cacheGroup = 'namespace_module';
$useCache = Mage::app()->useCache($cacheGroup);
if (true === $useCache) {
    // Cache is active
} else {
    // Cache is not active
}

最新更新