5

多言語 Magento ストアが Varnish とどのように連携するか。ワニスで利用可能な構成はありますか? Cookie に基づいてキャッシュを作成できますか?

4

2 に答える 2

6

言語が異なる URL にあることを気にしない場合は、Turpentine でこれを処理できます: https://github.com/nexcess/magento-turpentine/issues/36

すぐに使用できるように動作させたい場合は、続けてください。

VCL リファレンスで varnish が has を生成する方法を変更する必要があります: https://www.varnish-cache.org/trac/wiki/VCLExampleCachingLoggedInUsers

これを変更して、言語セレクターに基づいて Magento が設定するストア Cookie も考慮に入れます。(ここでの動作に従います:http: //demo.magentocommerce.com)残念ながら、VarnishはCookieをサーバーに返さないか、Cookieが飛び回っているのを確認したときに物事をキャッシュしない傾向があるため、注意が必要です

これには、Cookie の値とデフォルトの URL およびホストに基づく Varnish キャッシュがあります。

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 をサーバーに送り返す必要がある場合があります。

もう 1 つのオプションは、Cookie を使用して任意のヘッダーのキャッシュを変更することです。これを X-Mage-Lang と呼びます。

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 を拡張して、「store」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;
}

Cookie の代わりに $_SERVER['X-Mage-Lang'] に現在のストアを設定します。

于 2013-04-30T19:21:04.070 に答える