magento
Magento Caching
Sök…
Hur cachar du anpassade data till 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;
Rengör cache efter cache-ID
Mage::app()->removeCache($cacheId);
Spola alla Magento-cacheposter
Mage::app()->cleanCache()
eller:
Mage::app()->getCacheInstance()->flush();
Använd Redis som cache-backend
Redis konfiguration:
- Installera redis (2.4+ krävs)
- Installera phpredis
- Installera Magento-förlängningen
Cm_Cache_Backend_Redis
(endast för Magento 1.7 och senare) - Redigera din
app/etc/local.xml
:
<global>
...
<cache>
<backend>Cm_Cache_Backend_Redis</backend>
<backend_options>
<server>127.0.0.1</server> <!-- or absolute path to unix socket -->
<port>6379</port>
<persistent></persistent>
<database>0</database>
<password></password>
<force_standalone>0</force_standalone>
<connect_retries>1</connect_retries>
<automatic_cleaning_factor>0</automatic_cleaning_factor>
<compress_data>1</compress_data>
<compress_tags>1</compress_tags>
<compress_threshold>20480</compress_threshold>
<compression_lib>gzip</compression_lib> <!-- Supports gzip, lzf and snappy -->
</backend_options>
</cache>
...
</global>
Modified text is an extract of the original Stack Overflow Documentation
Licensierat under CC BY-SA 3.0
Inte anslutet till Stack Overflow