-
StackOverflow 文档
-
magento 教程
-
Magento 缓存
-
如何将自定义数据缓存到 Magento 中
const CACHE_TAG_NAMESPACE_MODULE = "YOUR_MODULES_CACHE_TAGS";
$cacheGroup = 'namespace_module';
$useCache = Mage::app()->useCache($cacheGroup);
if (true === $useCache) {
$cacheId = 'unique_name';
if ($cacheContent = Mage::app()->loadCache($cacheId)) {
$html = $cacheContent;
return $html;
} else {
try {
$cacheContent = $html;
$tags = array(model::CACHE_TAG_NAMESPACE_MODULE);
$lifetime = Mage::getStoreConfig('core/cache/lifetime');
Mage::app()->saveCache($cacheContent, $cacheId, $tags, $lifetime);
} catch (Exception $e) {
// Exception = no caching
Mage::logException($e);
}
return $html;
}
}
// Default:
return $html;