수색…


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;

캐시 ID로 캐시 정리

Mage::app()->removeCache($cacheId); 

Magento 캐시 항목 모두 플러시

Mage::app()->cleanCache()

또는:

Mage::app()->getCacheInstance()->flush();

Redis를 캐시 백엔드로 사용하십시오.

Redis 구성 :

  1. redis 설치 (2.4 이상 필요)
  2. phpredis 설치
  3. Magento 확장 Cm_Cache_Backend_Redis 설치하십시오 (Magento 1.7 이하에만 해당).
  4. 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
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow