zoukankan      html  css  js  c++  java
  • 牛叉的多级缓存

    # nginx.conf
    
    http {
        # you do not need to configure the following line when you
        # use LuaRocks or opm.
        lua_package_path "/path/to/lua-resty-mlcache/lib/?.lua;;";
    
        # 'on' already is the default for this directive. If 'off', the L1 cache
        # will be inefective since the Lua VM will be re-created for every
        # request. This is fine during development, but ensure production is 'on'.
        lua_code_cache on;
    
        lua_shared_dict cache_dict 1m;
    
        init_by_lua_block {
            local mlcache = require "resty.mlcache"
    
            local cache, err = mlcache.new("my_cache", "cache_dict", {
                lru_size = 500,    -- size of the L1 (Lua VM) cache
                ttl      = 3600,   -- 1h ttl for hits
                neg_ttl  = 30,     -- 30s ttl for misses
            })
            if err then
    
            end
    
            -- we put our instance in the global table for brivety in
            -- this example, but prefer an upvalue to one of your modules
            -- as recommended by ngx_lua
            _G.cache = cache
        }
    
        server {
            listen 8080;
    
            location / {
                content_by_lua_block {
                    local function callback(username)
                        -- this only runs *once* until the key expires, so
                        -- do expensive operations like connecting to a remote
                        -- backend here. i.e: call a MySQL server in this callback
                        return db:get_user(username) -- { name = "John Doe", email = "john@example.com" }
                    end
    
                    -- this call will try L1 and L2 before running the callback (L3)
                    -- the returned value will then be stored in L2 and L1
                    -- for the next request.
                    local user, err = cache:get("my_key", nil, callback, "John Doe")
    
                    ngx.say(user.username) -- "John Doe"
                }
            }
        }
    }
  • 相关阅读:
    js 提示框的实现---组件开发之(一)
    js 原型链
    js 哈希路由原理实现
    js 弹窗的实现
    js 滑动门的实现
    Delphi IDFtp用法,包含断点续传
    memortstream Base64编码和filestream base64编码不同
    Delphi另一个多线程函数:BeginThread用法
    delphi 讲的比较详细的多线程(推荐)
    多线程简单实用
  • 原文地址:https://www.cnblogs.com/justart/p/12384920.html
Copyright © 2011-2022 走看看