---------------------缓存:
1、php的fastcgi缓存 fastcgi_cache
见上面配置:php fastcgi的缓存:
http://www.360doc.com/content/15/0816/14/552866_492084033.shtml
https://zhangge.net/5042.html
https://github.com/FRiCKLE/ngx_cache_purge/
2、缓存代理页面 proxy_pass_cache
见上面配置:proxy代理缓存
实现:本地文件的形式
http://www.open-open.com/lib/view/open1431254539701.html
https://www.aliyun.com/zixun/content/3_12_518236.html
3、proxy_cache的配置,可以通过挂载一块内存作为缓存的存储空间。
参考http://nginx.org/cn/docs/http/ngx_http_proxy_module.html。
4、nginx的ngx.var.dict+lock实现 减少对后段服务的访问。解决缓存失效风暴
实现:redis,mem
lua-resty-lock锁机制
for-cache-locks避免雪崩
https://github.com/openresty/lua-resty-lock#for-cache-locks
主动异步过期缓存
https://github.com/lloydzhou/lua-resty-cache
srcache-nginx-module
https://github.com/openresty/srcache-nginx-module
这个模块支持和另一个模块配合将页面缓存写入redis集群
https://segmentfault.com/a/1190000003874328
5、resty.lrucache lua自身代码实现的cache
local lrucache = require "resty.lrucache"
-- we need to initialize the cache on the lua module level so that
-- it can be shared by all the requests served by each nginx worker process:
local c = lrucache.new(200) -- allow up to 200 items in the cache
if not c then
return error("failed to create the cache: " .. (err or "unknown"))
end
function _M.go()
c:set("dog", 32)
c:set("cat", 56)
ngx.say("dog: ", c:get("dog"))
ngx.say("cat: ", c:get("cat"))
c:set("dog", { age = 10 }, 0.1) -- expire in 0.1 sec
c:delete("dog")
end
文档:https://github.com/openresty/lua-resty-lrucache
注意:
修改系统内核的修改通过设置如下参数来设置内存阀值
sysctl -w vm.extra_free_kbytes=6436787
sysctl -w vm.vfs_cache_pressure=10000