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.

Can't make it work with custom storage

See original GitHub issue

Describe the bug

I read all the docs, all examples, all Google and most of the issues 😉 And I still can’t make custom storage work.

To Reproduce

For example (I took the code from an other issue yet it works the same as my original code that used file system):

my-cache.js:

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) => {
    console.log(value); // HERE
    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,
});

function getAxiosWithCache() {
  return INSTANCE;
}
module.exports = { getAxiosWithCache };

Usage:

const { getAxiosWithCache } = require('./my-cache');
const axios = getAxiosWithCache();

async function parseSearchPage(url) {
  const res = await axios.get(url);
  const html = res.data;
  console.log(html); // HERE 2
}

Actual behavior

HERE 2 reports the downloaded URL’s content.

HERE reports only:

{
  state: 'loading',
  previous: 'empty',
  data: undefined,
  createdAt: undefined
}

Expected behavior

HERE reports the downloaded URL’s content, just as HERE 2 does

Additional context

  • Axios: v0.27.2
  • Axios Cache Interceptor: v0.10.7
  • What storage is being used: custom
  • Node Version: v16.16.0

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
lukaszmncommented, Oct 19, 2022

Thank you for the detailed explanation, I totally agree with this behavior.

I did not notice it earlier even though I thought I had enabled the debug mode - I set only debug: console.log, but I did not notice I should have also changed the import path to .../dev. Thanks again.

1reaction
ahn-nathcommented, Nov 8, 2022

This makes more sense. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot get QSettings to read from custom storage format
I'm trying to create a custom format for QSettings , but I can't get it to read from the storage. In the code...
Read more >
Detect non-reused custom storage classes - MATLAB & Simulink
Description. Select the diagnostic action to take when your model contains a Reusable custom storage class that the code generator cannot reuse with...
Read more >
Custom Storage Solutions to Consider During a Remodel
Investing in a home office custom storage system will create a structured, unique and personalized work environment that fits all your needs.
Read more >
Upgrade to iCloud+ - Apple Support
Upgrade to iCloud+. With iCloud, you automatically get 5GB of free iCloud storage for your photos, videos, files, and more. If you want...
Read more >
Set storage limits - Google Workspace Admin Help
If you don't set storage limits, users in your organization won't see ... To get a warning if a group member exceeds the...
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