I use a different approach: configuration is stored in shared dictionary as JSON and in workers in deserialized form. Each time I want to get configuration I compare version stored in worker with version in shared dictionary. When my version is too old I update worker-level cache. It works as long as entire configuration can be deserialized in a sane amount of time, or if it can be divided into small parts that can be managed that way. It has an advantage of being simple to work with.
A simplified example:
-- config.lua
local M = {}
-- worker-level cache
local local_data_version = 0
local local_data
-- ngx.shared.my_config.data_json and ngx.shared.my_config.version are periodically set in ngx.timer worker
function M.get_full_config()
local shared_dict_config = ngx.shared.my_config
local shared_data_version = shared_dict_config.version
if shared_data_version > data_version then
data_version = shared_data_version
data = ""> end
return data
end
return M
W dniu niedziela, 13 października 2019 16:19:56 UTC+2 użytkownik Hadi Abbasi napisał:
Hello friends...
I have a data structure in my openresty api.
the information on the dictionary is so important for my cdn moment by moment, I always refresh its data by current available admins settings every 5 minutes.
I can check all of removable and stale data using my algorithms!
(like collecting old keys in tmp array and iteration on new data array and removing current available keys from that tmp array and at the end of iteration, I have removable properties in my tmp array so I can remove all of removable information from my data structure)
but just I wanna know if I can renew my shared dictionary using a way like:
----------nginx.conf
lua_shared_dict data_struct 50m;
------ update data structure location
local new_shared_dictionary = {}
new_shared_dictionary ["property1"] = x
new_shared_dictionary ["property2"]= y
ngx.shared.data_struct = new_shared_dictionary
I think I have no any simple choice like my example! am I right?
good luck...
Best,
Hadi