apicache icon indicating copy to clipboard operation
apicache copied to clipboard

Missing redis support for groups (create/delete)

Open avalosrios opened this issue 5 years ago • 2 comments

apicache only works for apps running in a single server as it uses local memory to store key names and groups. When deleting groups on an app running on multiple physical servers (load balancing) it is impossible to expire a group as the server receiving the request might or might not have the complete index

What would be the recommended implementation for apps like this with redis ? We could store the index as a SET in redis and do similar operation when clearing the cache. Maybe an easier way to support this use case is to allow a prefix option ?

avalosrios avatar May 17 '19 21:05 avalosrios

I've just faced the same problem.

The prefix option maybe isnt a good idea because the redis client instantiation can already define a prefix.

So maybe just a mandatory prefix argument to clear function when trying to clear all keys (when using redis). When using redis, i think the index.all doesn't need to be stored in memory at all nor in redis as one node process may keep a stale copy when other process clear keys. And the clear(all) function could use scans with MATCH prefix* each followed by dels to clear all keys from apicache

When using redis, the index.groups from req.apicacheGroup also shouldn't be stored in memory as apicache running at process A won't be able to clear keys from a group created at process B. So, groups should be Sets stored in and fetched from redis.

arthurfranca avatar Mar 20 '20 19:03 arthurfranca

I've ended up implementing my own api-cache version for this same reason, I don't think this library is able to support multi tenant apps as it is.

avalosrios avatar Mar 20 '20 20:03 avalosrios