ngx缓存失效时候都是通过proxy_cache_valid定义多长时间失效,以及通过上游服务发送来的响应的头部
比如Cache-Control,X-Accel定义缓存何时失效,这些缓存何时失效基于一个时间段后,像一个定时器一样过期
立刻使ngx缓存失效
upserver.conf
server {
listen 8012;
default_type text/plain;
root html;
location / {
}
}
cache.conf
proxy_cache_path /data/nginx/tmpcache levels=2:2 keys_zone=two:10m loader_threshold=300
loader_files=200 max_size=200m inactive=1m;
server {
server_name cache.taohui.tech;
listen 8097;
root html/;
error_log logs/cacherr.log debug;
location ~ /purge(/.*) {
proxy_cache_purge two $scheme$1;
}
location /{
proxy_cache two;
proxy_cache_valid 200 1m;
add_header X-Cache-Status $upstream_cache_status;
proxy_cache_key $scheme$uri;
proxy_pass http://localhost:8012;
}
编译nginx: ./configure --add-module=../ngx_cache_purge
第三方模块:https://github.com/FRiCKLE/ngx_cache_purge
使用purge模块强制清空缓存