arthurfiorette / axios-cache-interceptor

📬 Small and efficient cache interceptor for axios. Etag, Cache-Control, TTL, HTTP headers and more!
https://axios-cache-interceptor.js.org
MIT License
690 stars 57 forks source link

Does this work in a multi-process environment? #925

Open mahnunchik opened 3 days ago

mahnunchik commented 3 days ago

What happened?

I quickly ran through the code and it looks like the module will not work correctly with cache if used with persistent storage (Redis for example https://axios-cache-interceptor.js.org/guide/storages#node-redis-storage) in a multi-process environment.

axios-cache-interceptor version

1.6.1

Node / Browser Version

20

Axios Version

1.7.7

What storage is being used

Another one

Relevant debugging log output

-
arthurfiorette commented 3 days ago

What are your assumptions on why this wouldn't work in a multi process environment? The only thing that shouldn't work is request deduplication when each of them are being used in a different process.

mahnunchik commented 3 days ago

@arthurfiorette Exactly this case! Identical simultaneous requests from 2+ processes.

It looks like in the current implementation the second+ request will fail with an error.

arthurfiorette commented 3 days ago

Since the waiting list is now just a promise map that resolves with nothing, that could change to an event emitter interface that could be extended by your redis instance to emit events real time.

Are you up to a PR? remember to add unit tests.

This PR will be a good read

mahnunchik commented 3 days ago

Actually I'm working with MongoDB as a storage provider, there is no simple way to emit event between instances.

arthurfiorette commented 3 days ago

if your storage provider isn't capable of sending/receiving events, there's not much we would be able to do anyways... If your case is highly needed, lookup the cost of actually running a redis instance as a cache provider.