2013-04-30 18 views

risposta

5

Se non ti dispiace le lingue essere a diversi URL, trementina in grado di gestire questo per voi: https://github.com/nexcess/magento-turpentine/issues/36

se si vuole che si comportino come fanno fuori dalla scatola, lascia andare avanti.

si deve modificare il modo in vernice genera l'ha nel vostro VCL Riferimento: https://www.varnish-cache.org/trac/wiki/VCLExampleCachingLoggedInUsers

Vorremmo modificare questo anche prendere in considerazione il cookie negozio che insiemi Magento basano sulla selezione della lingua. (Seguendo il comportamento qui: http://demo.magentocommerce.com) Sfortunatamente questo diventa complicato poichè Varnish tende a non passare i cookie al server o non memorizzare nella cache quando vede i cookie volare intorno a

Questo avrebbe cache di Varnish basata sul valore del cookie così come l'URL predefinito e host:

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); 
} 

Ma, con questo metodo potrebbe essere necessario modificare il resto della tua VCL per memorizzare nella cache la pagina in modo corretto e inviare il cookie al server

Un'altra opzione è usare il cookie per variare il caching su un header arbitrario, chiamiamolo X-Mage-L ang:

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=(.*?))(?:;|$)"); 
} 

Questo modello è utilizzato anche per il rilevamento dei dispositivi con vernice: https://github.com/varnish/varnish-devicedetect/blob/master/INSTALL.rst

Poi, si dovrebbe estendere Mage_Core_Model_App per utilizzare questa intestazione invece del cookie 'negozio'. In Magento CE 1.7 la sua _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; 
} 

si dovrebbe impostare il negozio corrente $ _SERVER [ 'X-Mage-Lang'] invece del cookie

+0

L'utilizzo della memorizzazione nella cache dei cookie si applica solo a un utente. –

+0

Non è un cookie di sessione, sta innescando il valore del cookie che ha la lingua in esso – timbroder

+0

Ok, mio ​​errore. Bella panoramica sempre. –

1

Add seguenti righe in vernice Config,

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

qual è l'effetto di queste righe? È la migliore o la risposta più breve? ;) – fbtb

Problemi correlati