apicache
apicache copied to clipboard
Missing redis support for groups (create/delete)
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 ?
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 scan
s with MATCH
prefix* each followed by del
s 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.
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.