博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
varnish-4.x VCL之强制cache miss
阅读量:4574 次
发布时间:2019-06-08

本文共 2434 字,大约阅读时间需要 8 分钟。

varnish-4.x VCL之强制cache miss
sub vcl_recv {
    set req.hash_always_miss = true; 
}
最前面的某段vcl_recv写入
 set req.hash_always_miss = true,即启用强制cache miss
这样varnish会把所有的请求都miss掉,直接丢到后端的web server,将最新的内容返回给客户端
并缓存一份最新的副本到varnish本地,注意,仅仅只是缓存,给客户端的永远最最新的内容
注意: 因为缓存多个副本,随着时间的推移,消耗内存也会逐渐增加,调试时可以用到
vcl 4.0;
import std;
import directors;
probe healthcheck_nginx {
    .url = "/healthy.jpg";
    .timeout = 3s;
    .interval = 5s;
    .window = 5;
    .threshold = 3;
}
probe healthcheck_apache {
    .url = "/healthy.jpg";
    .timeout = 3s;
    .interval = 5s;
    .window = 5;
    .threshold = 3;
}
backend nginx {
    .host = "192.168.192.10";
    .port = "8080";
    .connect_timeout = 3s;
    .first_byte_timeout = 5s;
    .between_bytes_timeout = 5s;
    .max_connections = 30000;
    .probe = healthcheck_nginx;
}
backend apache {
    .host = "192.168.192.10";
    .port = "8081";
    .connect_timeout = 3s;
    .first_byte_timeout = 5s;
    .between_bytes_timeout = 5s;
    .max_connections = 3000;
    .probe = healthcheck_apache;
}
sub vcl_init {
    new round_robin_director = directors.round_robin();
    round_robin_director.add_backend(apache);
    round_robin_director.add_backend(nginx);
    new random_director = directors.random();
    random_director.add_backend(nginx, 10);
    random_director.add_backend(apache, 5);
    new hash_director = directors.hash();
    hash_director.add_backend(nginx, 10);
    hash_director.add_backend(apache, 5);
}
sub vcl_recv {
    set req.hash_always_miss = true; 
}
sub vcl_recv {
    if (req.method == "PRI") {
       
        return (synth(405));
    }
    if (req.method != "GET" &&
        req.method != "HEAD" &&
        req.method != "PUT" &&
        req.method != "POST" &&
        req.method != "TRACE" &&
        req.method != "OPTIONS" &&
        req.method != "DELETE") {
           
            return (pipe);
    }
    if (req.method != "GET" && req.method != "HEAD") {
       
        return (pass);
    }
    if (req.http.Authorization || req.http.Cookie) {
       
        return (pass);
    }
    return (hash);
}
acl purgers {
    "127.0.0.1";
    "192.168.0.0"/24;
}
sub vcl_recv {
    # allow PURGE from localhost and 192.168.0...
    if (req.restarts == 0) {
        unset req.http.X-Purger;
    }
    if (req.method == "PURGE") {
        if (!client.ip ~ purgers) {
            return (synth(405, "Purging not allowed for " + client.ip));
        }
        return (purge);
    }
    #set req.backend_hint = round_robin_director.backend();
    set req.backend_hint = hash_director.backend(req.http.cookie);
}
sub vcl_purge {
    set req.method = "GET";
    set req.http.X-Purger = "Purged";
    return (restart);
}
sub vcl_deliver {
    if (req.http.X-Purger) {
        set resp.http.X-Purger = req.http.X-Purger;
    }
}

转载于:https://www.cnblogs.com/lixuebin/p/10814129.html

你可能感兴趣的文章
我的面试问题记录
查看>>
函数PARSENAME使用和截取字符串
查看>>
关乎性能的判断,请作出果断选择
查看>>
判断是否包含指定的字符
查看>>
[Html5] HTML5 开发手机应用
查看>>
[工具] 各种主流 SQLServer 迁移到 MySQL 工具对比
查看>>
(二)Maven 基本概念——依赖、生命周期、仓库管理、聚合&继承
查看>>
py4CV例子3Mnist识别和ANN
查看>>
【4Opencv】如何识别出轮廓准确的长和宽
查看>>
现货黄金交易计划摸索
查看>>
Django中国|Django中文社区——python、django爱好者交流社区
查看>>
java中的toArray()
查看>>
java数据库之JDBC
查看>>
C语言 strcpy,memcpy,memmove,memccpy函数
查看>>
SqlSession 内部运行
查看>>
C语言一个小程序的bug疑问 数组相关[已解决]
查看>>
空指针与野指针的区别
查看>>
Ubuntu的root用户问题
查看>>
Linux启动新进程的几种方法及比较[转]
查看>>
使用Python定义类及创建对象
查看>>