On Tuesday, January 13, 2015 at 6:43:25 AM UTC+11, agentzh wrote:
Hello!
Hi - and thanks for the quick and friendly response!
I'm not sure what do you exactly mean by "static permissions". If they
are truly static and not subject to change often, then you can just
generate a JSON file and load it via lua-cjson (or some else Lua JSON
library) in your Lua code (like loading in the context init_by_lua).
Well, by 'static permissions', I meant something you could just copy to a file, or check in to GitHub for instance, that would be generated at the same time as the content. Hence the SQLite idea, as that can be represented as a file.
If these permission rules are subject to change often, then you can
just run a redis server (probably with persistence support enabled)
and use lua-resty-redis to talk to it nonblockingly.
The idea is that the permissions *could* change, just like the 'static html', but not very often. Reading from a JSON file could work, so long as I could get it to read an updated JSON file every so often, without having to restart or HUP the Nginx process. I'd rather not rely on having a Redis setup - the idea is you can just checkout the latest version of the content, and serve it with Nginx. No app servers, no databases, just Nginx, Lua plugin, and the right config. Certainly you could the setup with Redis DBs, page view counts and so forth, but I'd rather that it worked flawlessly when any of those extra pieces were down or failing.
It's much more efficient (and also much easier) to do the checking
upon every request in access_by_lua, for example. Please keep in mind
that file I/O syscalls are usually *much* more expensive compared to
pure memory computations in your Lua code.
I note Lua can access shared Nginx mem via a dict. Would it be possible to have a very lightweight process that polled a JSON file (or whatever), and updated that in memory dict? Basically I want a way to update a file, and for that to update what 'access_by_lua' decided, in a simple, non-blocking way. Perhaps just a simple bash script fastcgi, that span up to re-read the JSON file every so often?