question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Data value vanish after first cached value read access

See original GitHub issue

Setup:

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:closed
  • Created 2 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
Inoircommented, Mar 15, 2022

Yes this is fixed, works nice! thx alot!

1reaction
Inoircommented, Mar 15, 2022

Sorry ill look into this now, haven’t had time for it yet.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found