我在nginx中嵌入了一些Lua代碼。在這段代碼中,我從Redis緩存中獲取了一些小數據。現在我想知道,如果在nginx中使用ngx.shared
構造緩存這些數據(已經緩存在某種意義上)是一種好的做法?這樣做有什麼優點和缺點嗎?在僞代碼中,我希望有這樣的:在ngx中緩存Redis數據是一個好習慣.shared
local cache = ngx.shared.cache
local cached_key = cache:get("cached_key")
if cached_key == nil then
... get data from Redis
cache:set("cached_key", cached_key)
end
我認爲這個問題很模糊。谷歌搜索「ngx.shared.cache」返回字面上少於10個結果。你最好在適當的ML上問這個問題。 – cnst
我認爲,搜索'ngx.shared.cache'沒有意義,因爲在這種情況下,緩存是我自己的變量名稱。這個問題相當概念化 - 在現實世界中,他們是否緩存nginx緩存中的Redis(或memcached)數據以提供更高的性能。 – Jacobian