lua-resty-cache-purge

"用于在 Nginx 中清除缓存的 Lua 模块"

$ opm get iakuf/lua-resty-cache-purge

lua-resty-cache-purge

一个用于动态清除 Nginx 中缓存的 Lua 模块,支持自定义缓存路径和层级。

安装

要安装此模块,可以使用 OpenResty 包管理器 (opm)

    opm get iakuf/lua-resty-cache-purge
    

使用

Nginx 配置

将以下配置添加到您的 nginx.conf 文件中

    http {
        lua_package_path "/path/to/lib/?.lua;;";
    
        server {
            listen 80;
            server_name example.com;
    
            location /purge {
                content_by_lua_block {
                    local cache_purge = require "resty.cache_purge"
                    cache_purge.set_cache_path("/cache/nginx/steamCache/depot") -- Set cache path
                    cache_purge.set_levels(2, 2)  -- Set cache levels
                    cache_purge.purge_cache(ngx.var.arg_key)
                }
            }
        }
    }
    

清除缓存请求

要清除缓存,请发出类似以下的请求

    curl -sv http://127.0.0.1:8083/purge?key=http/depot/394360/chunk/763094ad824fac2c4ac7d912474533eeee075dfc
    
    

API

set_cache_path(path) 设置缓存的基础路径。

set_levels(level1, level2) 设置缓存的目录层级。

purge_cache(key) 清除给定键的缓存

许可证

MIT

作者

"傅凯 <iakuf@163.com>"

许可证

mit

版本