【问题标题】:Is it possible to prevent caching based on the size of the backend response in Varnish?是否可以根据 Varnish 中后端响应的大小来防止缓存?
【发布时间】:2016-06-22 10:58:15
【问题描述】:

我们正在缓存一个有问题的 IIS 服务器,该服务器有时只发送空响应(0 字节)而不是正确的响应。缓存这些响应将是一场灾难,我们无法解决问题,因为它不是我们的服务器。相反,我想指示 Varnish 如果后端响应为空(0 字节),则不要缓存它们。

阅读 VCL 参考 (https://www.varnish-cache.org/docs/4.0/reference/vcl.html) 我看不到任何明显的解决方法。

可以吗?

【问题讨论】:

    标签: caching varnish varnish-vcl varnish-4


    【解决方案1】:

    如果您想将其用作整数来查看是否大于或小于值,请使用 std。

    import std; 
    
    if (std.integer(beresp.http.content-length, 0) < 500) {
      #logic here 
    }
    

    【讨论】:

    【解决方案2】:

    响应的大小应作为 HTTP 标头提供。

    示例(vcl_backend_response):

    if (beresp.http.Content-Length == "0") {
        return(retry);   # Retries the request
    }
    

    或:

    if (beresp.http.Content-Length == "0") {
        beresp.uncacheable = true;   # Prevents object from being cached
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-31
      • 2010-09-29
      • 2017-01-19
      • 1970-01-01
      • 2015-06-18
      相关资源
      最近更新 更多