简体   繁体   English

清漆缓存和购物车

[英]Varnish Cache & Shopping Carts

I've been looking into Varnish recently and doing some heavy Google searching. 我最近一直在研究Varnish并进行一些重要的谷歌搜索。 We've recently set this up in anticipation for Christmas on our server that runs an ecommerce site. 我们最近在我们运行电子商务网站的服务器上预期了圣诞节。 We'll be having increased return visits over the next few weeks, so using Varnish seemed like a good idea. 我们将在未来几周内增加回访,所以使用Varnish似乎是一个好主意。

I was wondering if someone could clarify something for me - when using Varnish, if a user arrives for the first time it detects a new cookie (as sessions are used for the shopping cart) and caches the pages they visit. 我想知道是否有人可以为我澄清一些事情 - 当使用Varnish时,如果用户第一次到达它会检测到新的cookie(因为会话用于购物车)并缓存他们访问的页面。

However, if we wanted to cache more than a customers repeat visits, I saw on a seperate stackoverflow thread that editing the .vcl with the following will help it cache pages even if session_start is used: 但是,如果我们想要缓存超过客户重复访问,我在一个单独的stackoverflow线程上看到,使用以下内容编辑.vcl将帮助它缓存页面,即使使用了session_start:

     sub vcl_recv {
     unset req.http.Cookie;
     return (lookup);
     }

     sub vcl_fetch {
     unset beresp.http.Set-Cookie;
     set beresp.ttl = 24h;
     return(deliver);
     }

My question is - I'm a little confused as to the specifics of -what- would be cached. 我的问题是 - 我对缓存的具体内容感到有些困惑。 Would this cache someone's shopping cart as well, thus serving this to all visitors to that product page? 这会缓存某人的购物车,从而为该产品页面的所有访问者提供服务吗?

Apologies if I'm missing a basic point of Varnish here; 如果我在这里错过了Varnish的基本观点,我会道歉; worst case scenario it'll help take the load off for return visits, but caching more of the site would be even better! 在最糟糕的情况下,它可以帮助减轻回访的负担,但缓存更多的网站会更好!

Thanks very much in advance 首先十分感谢

Varnish will not (by default) cache pages with set Cookies. Varnish不会(默认情况下)使用设置Cookie缓存页面。 Cookies introduce state to HTTP and thus Varnish can't know whether or not the page has changed. Cookie将状态引入HTTP,因此Varnish无法知道页面是否已更改。

Your above code snippet though will not fix your issue. 您上面的代码段不会解决您的问题。 It will just remove Cookie headers altogether. 它只会完全删除Cookie标头。 (Ie you PHP backend will not receive session cookies.) (即PHP后端不会收到会话cookie。)

Depending on how exactly your site looks like, you would either want to: 根据您网站的确切位置,您可能希望:

  • Leave behavior as is: If you for example have some place on the page saying the username of the logged in user you don't want that to be cached. 保持行为不变:例如,如果您在页面上有一些位置,说明您不希望缓存登录用户的用户名。 Basically in this case Varnish will only cache contents for guest (ie users without sessions) 基本上在这种情况下,Varnish只会缓存来宾的内容(即没有会话的用户)
  • If you don't have such a user-dependent box on every page you can cache everything apart from the user-dependent (eg shopping cart) pages. 如果您在每个页面上都没有这样的依赖于用户的框,则可以将所有内容缓存在与用户相关的(例如购物车)页面之外。

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

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