缓存控制:验证缓存时是否可以忽略查询参数? [英] Cache-control: Is it possible to ignore query parameters when validating the cache?

查看:118
本文介绍了缓存控制:验证缓存时是否可以忽略查询参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以设置与反向代理通信的 cache-control 标头以在确定什么是唯一 uri 时忽略查询参数,或者简而言之:即使某些查询参数已更改,也验证缓存?

Is it possible to set a cache-control header communicating with a reverse proxy to ignore query parameters in determining what is a unique uri or in short: validate a cache even if some query parameters have changed?

有时,至少从服务器端的角度来看,查询参数与页面的呈现无关.例如,来自 Google Adwords 的所有 utm_* 变量.这些是页面上的 javascript 所必需的,因此您不想将它们剥离并重定向到缓存页面,但同时最好不要处理两个基本相同但具有不同 的 uriutm_* 参数在与反向代理通信时是唯一的.

Sometimes query parameters have nothing to do with the rendering of the page at least from a server side perspective. For instance all utm_* variables from Google Adwords. These are needed for the javascript on your page so you don't want to strip them away and redirect to a cached page but at the same time it would be advantageous not to treat two uri's which are basically the same but have different utm_* parameters as unique when communicating with a reverse proxy.

示例:

  1. http://www.example.com/search?sort=price

http://www.example.com/search?sort=price&utm_campaign=shoes

无论如何要告诉使用 HTTP 1.1 规范(即某种类型的 http 标头)的反向代理它可以将这两个页面视为相同的?

Is there anyway to tell the reverse proxy using the HTTP 1.1 spec (i.e. some type of http header) that it can just treat these two pages as the same?

推荐答案

您可以在 vcl_recv 中过滤查询字符串,并且还有一个 Varnish 模块 [1].

You can filter the query string in vcl_recv and there is also a Varnish module for that [1].

此外,您必须记住,在这种情况下,查询字符串参数顺序很重要 [2]

Also, you have to keep in mind that query string parameter order matters in this case [2]

另见此相关问题 [3]

See also this related question [3]

[1] https://www.varnish-cache.org/vmod/querystring

[2] http://cyberroadie.wordpress.com/2012/01/05/varnish-reordering-query-string/

[3] 剥离选择查询字符串属性/值对,以便清漆不会因它们而改变缓存

这篇关于缓存控制:验证缓存时是否可以忽略查询参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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