2013-04-30 67 views

回答

5

如果你不介意的語言處於不同的URL,松節油可以處理這個要求:https://github.com/nexcess/magento-turpentine/issues/36

如果你希望它們表現爲他們開箱即用,讓我們繼續前進。

您必須修改清漆如何產生在你的VCL 參考:https://www.varnish-cache.org/trac/wiki/VCLExampleCachingLoggedInUsers

我們要修改這個也考慮到基於語言選擇的Magento套店裏的cookie。 (下面的行爲在這裏:http://demo.magentocommerce.com)很不幸,這得到棘手清漆往往當它看到的cookies會基於cookie的值光油緩存飛來飛去

要麼不通過Cookie傳回服務器或不緩存東西以及默認的URL,主機:

sub vcl_hash { 
     hash_data(req.url); 
     hash_data(req.http.host); 

     if (req.http.Cookie ~ "(?:^|;\s*)(?:store=(.*?))(?:;|$)"){ 
       hash_data(regsub(req.http.Cookie, "(?:^|;\s*)(?:store=(.*?))(?:;|$)")); 
     } 

     return (hash); 
} 

但是,用這種方法,你可能需要調整您的VCL其餘正確緩存頁面和發送餅乾回服務器

另一種選擇是使用cookie來改變任意頭部的緩存,我們稱之爲X-Mage-L昂:

sub vcl_fetch { 
    #can do this better with regex 
    if (req.http.Cookie ~ "(?:^|;\s*)(?:store=(.*?))(?:;|$)"){ 
     if (!beresp.http.Vary) { # no Vary at all 
      set beresp.http.Vary = "X-Mage-Lang"; 
     } elseif (beresp.http.Vary !~ "X-Mage-Lang") { # add to existing Vary 
      set beresp.http.Vary = beresp.http.Vary + ", X-Mage-Lang"; 
     } 
    } 
    # comment this out if you don't want the client to know your classification 
    set beresp.http.X-Mage-Lang = regsub(req.http.Cookie, "(?:^|;\s*)(?:store=(.*?))(?:;|$)"); 
} 

此模式也可用於設備檢測清漆:https://github.com/varnish/varnish-devicedetect/blob/master/INSTALL.rst

然後,你將不得不延長Mage_Core_Model_App使用而不是「存儲」的Cookie此標題。在Magento CE 1.7的_checkCookieStore:

protected function _checkCookieStore($type) 
{ 
    if (!$this->getCookie()->get()) { 
     return $this; 
    } 

    $store = $this->getCookie()->get(Mage_Core_Model_Store::COOKIE_NAME); 
    if ($store && isset($this->_stores[$store]) 
     && $this->_stores[$store]->getId() 
     && $this->_stores[$store]->getIsActive()) { 
     if ($type == 'website' 
      && $this->_stores[$store]->getWebsiteId() == $this->_stores[$this->_currentStore]->getWebsiteId()) { 
      $this->_currentStore = $store; 
     } 
     if ($type == 'group' 
      && $this->_stores[$store]->getGroupId() == $this->_stores[$this->_currentStore]->getGroupId()) { 
      $this->_currentStore = $store; 
     } 
     if ($type == 'store') { 
      $this->_currentStore = $store; 
     } 
    } 
    return $this; 
} 

你會設置$ _ SERVER [ 'X-MAGE-郎'],而不是餅乾

+0

使用cookie解決方案緩存只適用於一個用戶。 – 2013-07-05 06:59:00

+0

這不是一個會話cookie,它觸發了其中有語言的cookie的值 – timbroder 2013-07-08 15:26:59

+0

好吧,我的錯誤。很好的概述。 – 2013-07-09 07:15:12

1

添加繼光油配置線,

if(beresp.http.Set-Cookie) { 
    return (hit_for_pass); 
} 
+0

什麼是這些線路的影響目前店?這是最好的還是最短的答案? ;) – fbtb 2015-03-03 17:13:22