清漆缓存 &购物车 [英] Varnish Cache & Shopping Carts

查看:21
本文介绍了清漆缓存 &购物车的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近一直在研究 Varnish,并在 Google 上进行了大量搜索.我们最近在运行电子商务网站的服务器上进行了设置,以期待圣诞节的到来.在接下来的几周内,我们的回访率将会增加,因此使用 Varnish 似乎是个好主意.

I've been looking into Varnish recently and doing some heavy Google searching. 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 时,如果用户第一次到达,它会检测到一个新的 cookie(因为会话用于购物车)并缓存他们访问的页面.

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.

但是,如果我们想要缓存的不仅仅是客户的重复访问,我在一个单独的 stackoverflow 线程上看到,使用以下内容编辑 .vcl 将有助于它缓存页面,即使使用 session_start:

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:

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

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

我的问题是 - 我对 -what- 将被缓存的细节有些困惑.这是否也会缓存某人的购物车,从而将其提供给该产品页面的所有访问者?

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?

抱歉,如果我在这里遗漏了 Varnish 的基本要点;在最坏的情况下,它有助于减轻回访的负担,但缓存更多网站会更好!

Apologies if I'm missing a basic point of Varnish here; worst case scenario it'll help take the load off for return visits, but caching more of the site would be even better!

非常感谢

推荐答案

Varnish 不会(默认情况下)缓存设置了 Cookie 的页面.Cookie 将状态引入 HTTP,因此 Varnish 无法知道页面是否已更改.

Varnish will not (by default) cache pages with set Cookies. Cookies introduce state to HTTP and thus Varnish can't know whether or not the page has changed.

您上面的代码片段虽然不能解决您的问题.它只会完全删除 Cookie 标头.(即您的 PHP 后端将不会收到会话 cookie.)

Your above code snippet though will not fix your issue. It will just remove Cookie headers altogether. (I.e. you PHP backend will not receive session cookies.)

根据您网站的具体外观,您可能想要:

Depending on how exactly your site looks like, you would either want to:

  • 保持行为不变:例如,如果您在页面上的某个地方显示已登录用户的用户名,则您不希望该用户名被缓存.基本上在这种情况下,Varnish 只会为来宾(即没有会话的用户)缓存内容
  • 如果您没有在每个页面上都有这样一个用户相关的框,您可以缓存除用户相关(例如购物车)页面之外的所有内容.

这篇关于清漆缓存 &购物车的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆