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
703 stars 58 forks source link

Bug: cloning do not work correctly with concurrency requests #899

Closed bupy7 closed 1 month ago

bupy7 commented 2 months ago

What happened?

Cloning do not work correctly with concurrency request: https://codesandbox.io/p/sandbox/j9cfcl

In this example I have changed "name" property in the request with "0" index key. Every next requests persist this change.

This is not happen if request do sequentially. To reproduce behavior - try runSequentially() and runSpreadly() functions in the code example.

axios-cache-interceptor version

v1.6.0

Node / Browser Version

any browser

Axios Version

v1.7.7

What storage is being used

Memory Storage

Relevant debugging log output

Everything you can take in the Codesandox example.
bupy7 commented 2 months ago

Workaround:

import axios from "axios";
import { buildMemoryStorage, setupCache } from "axios-cache-interceptor/dev";

const cachedAxios = setupCache(axios.create(), {
  storage: buildMemoryStorage(false),
});

cachedAxios.interceptors.response.use((v) => {
  return {
    ...v,
    data: v.data !== undefined ? JSON.parse(JSON.stringify(v.data)) : undefined,
  }
})
arthurfiorette commented 2 months ago

HI @bupy7, thanks for opening this request.

Would you want to open a PR? remember to add unit tests.

Taking a look at our existing unit tests is a good way to start and learn how its done.

arthurfiorette commented 1 month ago

Fixed in v1.6.1