2013-04-30 115 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