Dear list,
I'm trying to understand what is the best way to cache lua code across multiple HTTP requests.
Right now in my nginx.conf file I have (just the relevant portion):
========== \/ nginx.conf =============================
http {
lua_code_cache on;
lua_package_path "./?.lua;$prefix/lib/?.lua;#{= LUA_PACKAGE_PATH };;";
server {
location / {
content_by_lua 'require(\"main\").handler(ngx)';
}
}
}
========== /\ nginx.conf =============================
Then in my main.lua file, I define the handler but also have some initialization code, and call other modules that do initialization themselves (in this example, only config.lua).
========== \/ main.lua ===============================
function Main.handler(ngx)
ngx.print('hello')
end
return Main
========== /\ main.lua ===============================
My config.lua file is where various initializations happen, like reading various config files in directories, etc. In this file I also set some , like so:
========== \/ config.lua =============================
... various init script ...
Settings = {
name = "test"
}
========== /\ config.lua =============================
I thought that require statements actually cached lua code (i.e. these get put into packages.loaded['config']), so that the code inside of config.lua would run only once. It is not so: this file (and all of my long initialization scripts) get run on .
What is the recommended way of dealing with such situations?
Thank you,
r.