zoukankan      html  css  js  c++  java
  • cache.lua--自带加锁功能方式缓存击穿

    local key = ngx.re.match(ngx.var.request_uri,"/([0-9]+).html")

    local mlcache = require "resty.mlcache"
    local function fetch_shop(aaa)
    ngx.log(ngx.ERR,'-------L3----------',aaa)
    return 'id=10'
    end

    if type(key) == "table" then
    local cache,err = mlcache.new("cache_name","my_cache",{
    lur_size = 500, --设置缓存的个数
    ttl = 5, --缓存过期时间
    neg_ttl = 6, --L3返回nil的保存时间
    ipc_shm = "ipc_cache" --用于将L2的缓存保存到L1

    })
    if not cache then
    	ngx.log(ngx.ERR,"-------------mlcache err")
    end
    local shop_detail,err,level = cache:get(key[1],nil,fetch_shop,"123")
        if level == 3 then
            math.randomseed(tostring(os.time()))
        local expire_time = math.random(1,6)
            local res,err = cache:set(key[1],{ttl=expire_time},shop_detail)
        end
        ngx.say(shop_detail)
    

    end

  • 相关阅读:
    Codeforces 1009F Dominant Indices
    UOJ #35 后缀排序 哈希做法
    bzoj 3670 [Noi2014]动物园
    动态规划 笔记

    常用模块和面向对象 类
    常用模块
    包的使用和常用模块
    日志
    复习列表,模块
  • 原文地址:https://www.cnblogs.com/xivzhou/p/14495800.html
Copyright © 2011-2022 走看看