我的目标是将特定的查询字符串属性及其值添加到“白名单”中,以便Varnish不会在URL之间变化缓存。
示例:
示例:
Url 1: http://foo.com/someproduct.html?utm_code=google&type=hello
Url 2: http://foo.com/someproduct.html?utm_code=yahoo&type=hello
Url 3: http://foo.com/someproduct.html?utm_code=yahoo&type=goodbye
在上面的示例中,我想将"utm_code"列入白名单,但不包括"type"。因此,在第一个URL被访问后,我希望Varnish将缓存内容提供给第二个URL。
然而,在第三个URL的情况下,属性"type"的值不同,因此应该是Varnish缓存未命中。
我尝试了以下两种方法(在Drupal帮助文章中找到,但现在无法找到了),但似乎没有起作用。可能是因为我的正则表达式有误。
# 1. strip out certain querystring values so varnish does not vary cache.
set req.url = regsuball(req.url, "([\?|&])utm_(campaign|content|medium|source|term)=[^&\s]*&?", "\1");
# get rid of trailing & or ?
set req.url = regsuball(req.url, "[\?|&]+$", "");
# 2. strip out certain querystring values so varnish does not vary cache.
set req.url = regsuball(req.url, "([\?|&])utm_campaign=[^&\s]*&?", "\1");
set req.url = regsuball(req.url, "([\?|&])foo_bar=[^&\s]*&?", "\1");
set req.url = regsuball(req.url, "([\?|&])bar_baz=[^&\s]*&?", "\1");
# get rid of trailing & or ?
set req.url = regsuball(req.url, "[\?|&]+$", "");