如何caching与清漆后的请求?

我用docker清漆 – 看百万/清漆

GET请求很好!

但我不知道我必须设置cachingPOST请求的设置。

在谷歌,我发现很多post(从2010年或2011年),它说,POST请求不能caching与清漆 – 这种说法仍然正确?

或者有另一种方法来cachingPOST请求?

这里我的varnish.vcl设置:

vcl 4.0; backend default { ... } # Respond to incoming requests. sub vcl_recv { unset req.http.Cookie; } # Set a header to track a cache HIT/MISS. sub vcl_deliver { if (obj.hits > 0) { set resp.http.X-Varnish-Cache = "HIT"; } else { set resp.http.X-Varnish-Cache = "MISS"; } } # Not cache 400 - 500 status requests sub vcl_backend_response { if (beresp.status >= 400 && beresp.status <= 600) { set beresp.ttl = 0s; } } 

感谢帮助 !

目前Varnish 不能cachingPOST请求

AFAIK人试图cachingPOST请求失败。 看来,清漆最终转换成GET请求。

资料来源:

  • 博客 (有关如何使用Nginx的更多信息)
  • 清漆论坛

有一个清漆模块和教程cachingPOST请求。 这增加了将post主体添加到散列键并传递POST请求的能力。

VMOD可用于Varnish 4版本,包括以下function:

 buffer_req_body(BYTES size): buffers the request body if it is smaller than size. This function is a “better” (bug-free**) copy of std.CacheReqBody(), so please use this one instead of the one provided by the libvmod-std. Please note that retrieving req.body makes it possible to retry pass operations(POST, PUT). len_req_body(): returns the request body length. rematch_req_body(STRING re): regular expression match on request body. hash_req_body(): adds body bytes to the input hash key. 

https://info.varnish-software.com/blog/caching-post-requests-with-varnish https://github.com/aondio/libvmod-bodyaccess

请注意,在此VMOD的4.1分支中,使用内置的std.cache_req_body()而不是buffer_req_body() ,但是Varnish 4.1中的一个buffer_req_body()错误会破坏4.1分支。 https://github.com/varnishcache/varnish-cache/issues/1927

  • 把另一个ngnx / apache /任何一个未使用的端口
  • 将POST请求推送到该服务器
  • 在那里你把它们作为get请求转发给清漆,并获取结果
  • 通过中继服务器显示结果

可能会减慢整个过程 – 但是我们在这里说的是肮脏的解决方法吗? 希望这不是太疯狂的解决scheme..

Interesting Posts