在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):openresty/lua-resty-lrucache开源软件地址(OpenSource Url):https://github.com/openresty/lua-resty-lrucache开源编程语言(OpenSource Language):Lua 94.2%开源软件介绍(OpenSource Introduction):Namelua-resty-lrucache - Lua-land LRU cache based on the LuaJIT FFI. Table of Contents
StatusThis library is considered production ready. Synopsis-- file myapp.lua: example "myapp" module
local _M = {}
-- alternatively: local lrucache = require "resty.lrucache.pureffi"
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, err = lrucache.new(200) -- allow up to 200 items in the cache
if not c then
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")
c:flush_all() -- flush all the cached data
end
return _M # nginx.conf
http {
# only if not using an official OpenResty release
lua_package_path "/path/to/lua-resty-lrucache/lib/?.lua;;";
server {
listen 8080;
location = /t {
content_by_lua_block {
require("myapp").go()
}
}
}
} DescriptionThis library implements a simple LRU cache for OpenResty and the ngx_lua module. This cache also supports expiration time. The LRU cache resides completely in the Lua VM and is subject to Lua GC. As
such, do not expect it to get shared across the OS process boundary. The upside
is that you can cache arbitrary complex Lua values (such as deep nested Lua
tables) without the overhead of serialization (as with This library offers two different implementations in the form of two classes:
If the cache hit rate is relatively high, you should use the However, if the cache hit rate is relatively low and there can be a lot of
variations of keys inserted into and removed from the cache, then you should
use the MethodsTo load this library,
local lrucache = require "resty.lrucache" or local lrucache = require "resty.lrucache.pureffi" new
Creates a new cache instance. Upon failure, returns The The set
Sets a key with a value and an expiration time. When the cache is full, the cache will automatically evict the least recently used item. The optional The optional get
Fetches a value with the key. If the key does not exist in the cache or has
already expired, Starting from Starting from delete
Removes an item specified by the key from the cache. count
Returns the number of items currently stored in the cache including expired items if any. The returned This method was added in the capacity
Returns the maximum number of items the cache can hold. The return value is the
same as the This method was added in the get_keys
Fetch the list of keys currently inside the cache up to This function returns a Lua (array) table (with integer keys) containing the keys. When When provided with a This method was added in the flush_all
Flushes all the existing data (if any) in the current cache instance. This is
an Note however that the PrerequisitesInstallationIt is recommended to use the latest OpenResty release.
At least OpenResty 1.4.2.9 is required. Recent versions of OpenResty only
support LuaJIT, but if you are using an older version, make sure to enable
LuaJIT when building OpenResty by passing the If you want to use this library with your own Nginx build (with ngx_lua), then you need to ensure you are using ngx_lua 0.8.10 or greater. When not using an OpenResty release, you also need to configure the lua_package_path directive to add the path to your lua-resty-lrucache source tree to ngx_lua's Lua module search path, as in: # nginx.conf
http {
# only if not using an official OpenResty release
lua_package_path "/path/to/lua-resty-lrucache/lib/?.lua;;";
...
} and then load the library in Lua: local lrucache = require "resty.lrucache" CommunityEnglish Mailing ListThe openresty-en mailing list is for English speakers. Chinese Mailing ListThe openresty mailing list is for Chinese speakers. Bugs and PatchesPlease report bugs or submit patches by
AuthorYichun "agentzh" Zhang (章亦春) [email protected], OpenResty Inc. Shuxin Yang. Copyright and LicenseThis module is licensed under the BSD license. Copyright (C) 2014-2019, by Yichun "agentzh" Zhang, OpenResty Inc. Copyright (C) 2014-2017, by Shuxin Yang. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. See Also
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论