uber-archive / request-redis-cache

Make requests and cache them in Redis
Other
2 stars 2 forks source link

Explore better interfaces #4

Open twolfson opened 10 years ago

twolfson commented 10 years ago

As discussed in https://github.com/uber/request-redis-cache/pull/2/files#r12081163, there is room for improvement on the interface. We thought of adding to the constructor but that won't work since it will require an instance for every key. However, something that is more observer-like might work:

var cache = new RequestRedisCache({redis: redis});
cache.addGetter(key, ttl, method);
cache.get(key, options, cb);
twolfson commented 10 years ago

/cc @Raynos since he was on the initial comment thread

twolfson commented 10 years ago

Ah, I realized why I avoided the addGetter method. In the implementation, we have many keys that can mutate but maybe that is a problem we have to solve.

normal-key-with-hash-of-object-that-can-vary
// model-1-abcdee OR model-1-abcdef

As a result, it could lead to a lot of persisted methods when they are no longer needed =/

twolfson commented 10 years ago

Bonus points: The normal-key also varies on a per-user basis which adds even more to the redundancy.