請問lua-resty-lrucache是運行在Lua VM裡面,跨coroutine可以共享,但不能跨worker process的是嗎?
也就是說,如果兩次獨立的http request都連到同一個nginx worker,是否都能共享lrucache的資料?
在範例代碼裡面
location = /t {
content_by_lua '
-- alternatively: local lrucache = require "resty.lrucache.pureffi"
local lrucache = require "resty.lrucache"
local c = lrucache.new(200) -- allow up to 200 items in the cache
if not c then
ngx.say("failed to create the cache: ", err)
return
end
ngx.say("dog: ", c:get("dog"))
ngx.say("cat: ", c:get("cat"))
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:set() 之前先嘗試 c:get() 取出資料,我發現先前http請求所c:set()進去的資料,並不會在另一個http請求裡面被取出來
dog: nil
cat: nil
dog: 32
cat: 56
請問這是什麼原因呢?