Can't make it work with custom storage
See original GitHub issueDescribe 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:
- Created a year ago
- Comments:9 (4 by maintainers)
Top 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 >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
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.This makes more sense. Thank you.