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

  • 相关阅读:
    Dubbo 配置参数
    类文件结构

    shell script 编程入门
    OnePlus5刷 TWRP
    TimeUtil 工具类
    Outline 科学的上网
    HotSpot虚拟机的锁优化
    equals与hashCode
    Java中的动态代理
  • 原文地址:https://www.cnblogs.com/xivzhou/p/14495800.html
Copyright © 2011-2022 走看看