nickschot / lux-redis-cache

[WIP] Middleware implementation of a redis based cache for Lux
MIT License
8 stars 1 forks source link

throwing error in `addToRedis` breaks use with lux-unless #12

Open jamemackson opened 7 years ago

jamemackson commented 7 years ago

Here in addToRedis we're throwing an error if the request key is not found which will be the case anytime getFromRedis is skipped via lux-unless. I'm thinking that we should allow addToRedis to noop if the requestKey is not present.

I suppose we could also require the implementor to put addToRedis in a matching unless rule but that feels counter to how we're configuring everything in the beforeAction and letting those rules flow through.

nickschot commented 7 years ago

This needs some thought indeed. I like the idea of the error though the current implementation is somewhat flawed.

Adding:

    request[requestKey] = {
      enabled: enabled
    };

at the beginning of getFromRedis partially fixes the issue (in the old/current situation when enabled is false, you get the error, this fix avoids that) though this does not help w/ lux-unless. Let me think about this a bit.