简体   繁体   English

根据使用Varnish和Magento的cookie中存储的变量创建缓存

[英]Create cache depending on a variable stored in cookie with Varnish and Magento

let's say I have a variable, that can either be 1, 2 or 3, it is stored in a user cookie. 假设我有一个变量,可以是1、2或3,它存储在用户cookie中。 eg: foo=2 例如:foo = 2

The first time someone access pageX with foo=2, the page shall be cached. 首次有人使用foo = 2访问pageX时,应缓存该页面。 All next visitors with foo=2 in their cookie shall see the same version (hit). 接下来所有cookie中foo = 2的访问者都将看到相同的版本(匹配)。

The first time someone access pageX with foo=1, the page shall be cached (as a second version). 首次有人使用foo = 1访问pageX时,应缓存该页面(作为第二个版本)。 All next visitors with foo=1 in their cookie shall see this specific version (hit). 所有其Cookie中的foo = 1的下一个访问者都将看到此特定版本(命中)。

same principle with foo=3 foo = 3的相同原理

In other words, all pages of my website will have 3 versions, even if the same URL, one for each value of foo in visitor's cookie. 换句话说,我的网站的所有页面都将具有3个版本,即使是相同的URL,也就是访问者Cookie中foo的每个值所对应的版本。

Is this feasible? 这可行吗?

thanks, Rod 谢谢,罗德

I think the answer you are looking for can be found in the varnish docs https://www.varnish-cache.org/trac/wiki/VCLExampleCachingLoggedInUsers 我认为您正在寻找的答案可以在清漆文档中找​​到https://www.varnish-cache.org/trac/wiki/VCLExampleCachingLoggedInUsers

there is a good example in how to use a cookie variable to create a unique hash. 有一个很好的例子,说明如何使用Cookie变量创建唯一的哈希。

This could also be used to create different pages for the same url. 这也可以用于为同一网址创建不同的页面。 Be careful with the browsercache settings of the page. 注意页面的浏览器缓存设置。 May the page change by url and the browser cache is set to high you might get strange behaviour. 可能页面通过url更改并且浏览器缓存设置为高,可能会导致奇怪的行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM