Hello!
On Wed, Nov 20, 2013 at 8:55 PM, Mark Selby wrote:
> My use case, and I think a common one, for OpenResty is accessing Redis for
> cached content. Would it be a good use case to have "sorted params"
> available, so that
>
> /blah?q=cheese&page=3
> can easily become
> /blah?page=3&q=cheese
>
> This seems tricky to do in LUA for some reason, but would obviously be
> valuable for more cache hits on API's etc .... maybe with the ability to
> fairly easily ignore irrelevant params
> "irrelevant=&blah=somethingNotIrrelevant"
>
This is not tricky to do in Lua at all (BTW, it's Lua, not LUA). See
the documentation below for an example:
http://wiki.nginx.org/HttpSRCacheModule#Cache_Key_Preprocessing
Although in that example the arguments are not really sorted by keys,
the order of keys should be consistent due to the table hash algorithm
in Lua. Even if that's not good enough for you, it's not hard to do
explicit sorting yourself in Lua anyway.
> To chuck something into the pot, the ngx.sleep is brilliant - I'm now
> rewriting for the case where the cache gets cleared, and the first backend
> hit writes to Redis with metadata saying { pending: 100 } straight away
> (before processing anything), so on a busy site the first cache miss adds
> this for the appropriate URL, and subsequent request see this and ngx.sleep
> for that number of milliseconds before checking the cache again - avoiding
> lots of backend hits for the same content.
>
This sounds like exactly what the lua-resty-lock library is doing:
https://github.com/agentzh/lua-resty-lock
Maybe you don't have to reinvent the wheel here ;)
I'm cc'ing the openresty-en mailing list:
https://groups.google.com/group/openresty-en And you're recommended to
join the list and post further questions there (unless your mail has
sensitive information).
Thanks!
-agentzh