groupon / node-cached

A simple caching library for node.js, inspired by the Play cache API
BSD 3-Clause "New" or "Revised" License
94 stars 15 forks source link

Using express session as backend? #34

Open jasonkarns opened 8 years ago

jasonkarns commented 8 years ago

Just curious if anyone has attempted using an express request session as a backend. The sessions are already memcached, and leveraging the session would save a memcached call since the session will have already been hydrated before cached calls. I admit, it's a rather odd use case. Especially considering the weirdness for a Cache's backend to essentially be swapped out (as a single Cache would have its backend "swapped" for each request).

But curious if anyone else has attempted to use cached wherein a specific backend instance is supplied for each Cache method call.

jkrems commented 8 years ago

Interesting idea! I'm not aware of anyone doing that (yet). It might be possible to do it generically for "external object backed", e.g. an in-memory backend with "bring your own object".

The downside of "It's just one cache operation!" is that everything has to fit into one cache value. Which can become problematic for memcache in particular.

Maybe a "transaction mode" for caches would be a better fit for this problem (assuming it's not all data that's super small & user-specific)? E.g. some form of cache.multiGetOrElse has already been proposed in other places. It might also be possible to collect set operations and bulk them up.