EE 1.14.2 / CE 1.9.2 블록 캐싱 업데이트에는 고유하지 않은 캐시 키가 있습니다. 프론트 엔드에 중복 컨텐츠가 표시됩니다.


18

EE 1.14.2로 업그레이드했을 때 대부분의 일이 순조롭게 진행되었지만 다양한 프론트 엔드 페이지를 확인하기 시작했을 때 문제가 발생했습니다. 여러 하위 범주가있는 카탈로그 노드가 있으며 각 하위 범주에는 서로 다른 정적 블록이 있습니다. 업그레이드 후 캐시 플러시 후 가장 먼저 방문한 페이지는 다른 모든 페이지에 표시됩니다.

CE 1.9.2가 출시 될 때 이와 동일한 문제가 있는지는 모르겠지만 동일한 문제를 발견 할 수있는 사람들을 위해 솔루션을 여기에 추가하고 싶었습니다.

업데이트 : 여기 에서 확인 된 것처럼 CE 1.9.2에서 동일한 문제가 발생 했습니다 .


답변:


11

이것이 EE이기 때문에 Magento 지원을 활용할 수 있었지만 문제를 해결하고 가능한 한 빨리 해결책을 얻도록 돕기 위해 스스로 해결했습니다. Magento가 코드 변경을 제공했기 때문에 / app / code / local에있는 파일을 항상 복제하고 변경 사항을 적용 할 수는 있지만 실제 앱 / 코드 / 코어 파일에 적용하는 것이 좋습니다.

문제는 1.14.2에 추가 된 블록 캐싱 방법이 고유 캐시 키를 생성하지 않았기 때문에 카테고리 컨트롤러 공간에서 여러 블록을 사용했을 때 생성 된 캐시 키가 첫 번째 페이지 적중에만 고유했습니다. 모든 해당 페이지가 중복 된 콘텐츠를 표시하도록합니다.

수정 사항은 다음을 추가하는 것입니다 (추가를 둘러싼 컨텍스트를 표시하기 위해 diff 파일 형식으로 표시됨-이동 해야하는 +와 함께 줄을 추가하십시오).

72 행의 app / code / core / Mage / Cms / Block / Block.php에서 :

         }
         return $html;
     }
+
+    /**
+     * Retrieve values of properties that unambiguously identify unique content
+     *
+     * @return array
+     */
+    public function getCacheKeyInfo()
+    {
+        $blockId = $this->getBlockId();
+        if ($blockId) {
+            $result = array(
+                $blockId,
+                Mage::app()->getStore()->getCode(),
+            );
+        } else {
+            $result = parent::getCacheKeyInfo();
+        }
+        return $result;
+    }
 }

82 행의 app / code / core / Mage / Cms / Block / Widget / Block.php에서 :

                 $helper = Mage::helper('cms');
                 $processor = $helper->getBlockTemplateProcessor();
                 $this->setText($processor->filter($block->getContent()));
+                $this->addModelTags($block);
             }
         }

         unset(self::$_widgetUsageMap[$blockHash]);
         return $this;
     }
+
+    /**
+     * Retrieve values of properties that unambiguously identify unique content
+     *
+     * @return array
+     */
+    public function getCacheKeyInfo()
+    {
+        $result = parent::getCacheKeyInfo();
+        $blockId = $this->getBlockId();
+        if ($blockId) {
+            $result[] = $blockId;
+        }
+        return $result;
+    }
 }

나는이 문제를 볼 수있는 유일한 사람이라고 생각하지 않으며 CE 1.9.2에 표시되면 일부 사람들 에게이 문제를 해결하는 데 도움이되기를 바랍니다.


불행히도 어제 출시 된 CE 1.9.2로 만들지 않았으므로 업그레이드 후 고객 웹 사이트 중 하나 에서이 문제가 발생했습니다. 이 수정을 시도합니다.
— Marco Miltenburg

이것은 나를 위해 작동하지 않습니다
— Pixelomo

10

Magento Boogieman이 당신을 얻을 것이라는 것을 모두 알고 있기 때문에 우리는 올바른 방법으로 커스텀 모듈을 만들어야한다고 생각합니다! 코어를 변경하면 :)

다음 파일이 필요합니다. app/etc/modules/Bhupendra_Cms.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Bhupendra_Cms>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Cms/>
            </depends>
        </Bhupendra_Cms>
    </modules>
</config>

app/code/local/Bhupendra/Cms/etc/config.xml

<?xml version="1.0"?>
<config>
        <modules>
            <Bhupendra_Cms>
                <version>1.0.0</version>
            </Bhupendra_Cms>
        </modules>
        <global>
            <blocks>
                <cms>
                    <rewrite>
                        <block>Bhupendra_Cms_Block_Block</block>
                        <widget_block>Bhupendra_Cms_Block_Widget_Block</widget_block>
                    </rewrite>
                </cms>
            </blocks>
        </global>
</config>

app/code/local/Bhupendra/Cms/Block/Block.php

<?php
class Bhupendra_Cms_Block_Block extends Mage_Cms_Block_Block {

   public function getCacheKeyInfo()
    {

      $blockId = $this->getBlockId();
      if ($blockId) {
            $result = array(
                $blockId,
                Mage::app()->getStore()->getCode(),
            );
      } else {
           $result = parent::getCacheKeyInfo();
       }
       return $result;
   }

}

app/code/local/Bhupendra/Cms/Block/Widget/Block.php

class Bhupendra_Cms_Block_Widget_Block extends Mage_Cms_Block_Widget_Block
{
       /**
     * Storage for used widgets
     *
     * @var array
     */
    static protected $_widgetUsageMap = array();

    /**
     * Prepare block text and determine whether block output enabled or not
     * Prevent blocks recursion if needed
     *
     * @return Mage_Cms_Block_Widget_Block
     */
    protected function _beforeToHtml()
    {
        parent::_beforeToHtml();
        $blockId = $this->getData('block_id');
        $blockHash = get_class($this) . $blockId;

        if (isset(self::$_widgetUsageMap[$blockHash])) {
            return $this;
        }
        self::$_widgetUsageMap[$blockHash] = true;

        if ($blockId) {
            $block = Mage::getModel('cms/block')
                ->setStoreId(Mage::app()->getStore()->getId())
                ->load($blockId);
            if ($block->getIsActive()) {
                /* @var $helper Mage_Cms_Helper_Data */
                $helper = Mage::helper('cms');
                $processor = $helper->getBlockTemplateProcessor();
                $this->setText($processor->filter($block->getContent()));
                $this->addModelTags($block);
            }
        }

        unset(self::$_widgetUsageMap[$blockHash]);
        return $this;
    }

     /**
     * Retrieve values of properties that unambiguously identify unique content
     *
     * @return array
     */
    public function getCacheKeyInfo()
    {
        $result = parent::getCacheKeyInfo();
        $blockId = $this->getBlockId();
        if ($blockId) {
            $result[] = $blockId;
       }
        return $result;
   }
}

자세한 내용을 보려면 다음 블로그를 방문하십시오. https://www.milople.com/blogs/ecommerce/solved-magento-static-block-display-issue.html


작곡가와 함께 모듈로 포장하지 않는 이유는 무엇입니까?
— Aleksey Razbakov

나는이 게시물에 대해 그다지 많은 응답을 얻지 못했기 때문에 어떤 본문도 모듈에서 그것을 원하지 않는다고 생각했다
— Bhupendra Jadeja

아직 아무도이 문제가 없었습니다. 아직 아무도 새로운 마 젠토 버전을 사용하지 않습니다. 나는 테레빈 모듈에 문제가 없다면 그것을 사용하지 않을 것이다
— Aleksey Razbakov

이 모듈을 다운로드 할 수있는 링크를 추가했습니다
— Bhupendra Jadeja

github.com/progammer-rkt/Rkt_SbCache와 같은 modman
— Aleksey Razbakov

4

CMS 블록 캐싱에는 한 가지 문제가 더 있는데, 위에서 주어진 코드로 해결되지 않습니다.

CMS 블록에서 보안 URL 및 {{media}} 태그를 사용하는 경우 Magento가 캐시에서 안전하지 않은 링크를 제공하므로 브라우저에서 "안전하지 않은 콘텐츠 경고"메시지가 표시됩니다.

이를 해결하려면 캐시 정보 태그를 하나 더 추가해야합니다.

(int)Mage::app()->getStore()->isCurrentlySecure(),

1

이 버그는이 작은 확장명으로도 고칠 수 있습니다 (핵심 파일을 편집하거나 블록을 다시 쓸 필요가 없습니다) :

https://github.com/progammer-rkt/Rkt_SbCache

또한 안전하지 않은 내용 경고를 피하기 위해 @AdvancedLogic에서 언급 한 줄이 포함되어 있습니다.

(int)Mage::app()->getStore()->isCurrentlySecure()


이것은 어떻게 든 1 블록에 대해 작동하지 않았다
— Aleksey Razbakov

어느 블록에? 이해가되지 않습니다. 좀 더 구체적으로 말씀해 주시겠습니까?
— zitix

하나의 정적 블록입니다. 구체적이지 않습니다. 나는 심지어 그것이 무작위 블록이라고 생각했습니다. HTML이 잘못되었습니다. 이 블록에 대해 잘못된 캐시가 사용 된 것 같습니다. 나는 더 구체적으로하는 방법을 모른다.
— Aleksey Razbakov
당사 사이트를 사용함과 동시에 당사의 쿠키 정책과 개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.