Data value vanish after first cached value read access
See original GitHub issueSetup:
const instance = setupCache(axios.create(), { ttl: 2000 });
so using the internal memory storage. didnt test any other storages. so first excution of the request is fine. 2nd is also good, after this the data value vanishes somehow out of the storage without trigger any function call on the storage itself (did console logs on find, set, remove => not getting called)
So this may be project specific, casue we are working alot with references in our system. Since references are totaly fine, there should be an mechanism to store and get an shallow copy of the data value.
So for now my current workaround for this is make an own memory storage:
const CACHE = new Map();
const STORAGE = buildStorage({
find: (key) => {
const found = CACHE.get(key);
if (found?.data) {
return { ...found, data: JSON.parse(JSON.stringify(found.data)) };
}
return found;
},
set: (key, value) => {
if (value?.data) {
CACHE.set(key, {
...value,
data: JSON.parse(JSON.stringify(value.data)),
});
} else {
CACHE.set(key, value);
}
},
remove: (key) => {
CACHE.delete(key);
},
});
const INSTANCE = setupCache(axios.create(), {
ttl: 2000,
storage: STORAGE,
});
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Reading and writing data to the cache
If you include a field in query but don't include a value for it in data , the field's current cached value is...
Read more >Access cache formats for SharePoint lists and document ...
Discusses Access cache formats for SharePoint lists and document libraries and performance improvements in Access 2010 and Access 2007.
Read more >Read-Through, Write-Through, Write-Behind Caching and ...
In the Write-Behind scenario, modified cache entries are asynchronously written to the data source after a configurable delay, whether after 10 seconds, 20 ......
Read more >VCL Basics - The Varnish Book
Before Varnish runs vcl_fetch , the beresp.ttl variable has already been set to a value. It will use the first value it finds...
Read more >What Is Cached Data? Why & How Should You Clear It?
Cached data are bits of information stored on your computer or smartphone to reduce load times. Can cached data be a security risk?...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes this is fixed, works nice! thx alot!
Sorry ill look into this now, haven’t had time for it yet.