You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was trying to cache some semi-expensive network calls to npm APIs and noticed I get errors if I set the cache key to something with a "/" in it (like a scoped package name). It looks like eleventy-cache-assets/AssetCache is treating the backslash as a file path delimiter when saving the file, which them blows up since there presumably isn't an ".cache/eleventy-cache-assets-@11ty/" folder.
// src/_data/test.jsconst{ AssetCache }=require("@11ty/eleventy-cache-assets");module.exports=asyncfunction(){// This seems to be the issue here (the "/" specifically).constasset=newAssetCache("@11ty/eleventy");if(asset.isCacheValid("1h")){returnasset.getCachedValue();}constvalue="Johnny Cache";awaitasset.save(value,"json");returnvalue;};
OUTPUT
npm run build
> [email protected] build /private/tmp/11ty-cache-asset-slug
> eleventy
> ENOENT: no such file or directory, open '/private/tmp/11ty-cache-asset-slug/.cache/eleventy-cache-assets-@11ty/eleventy.json'
`Error` was thrown:
Error: ENOENT: no such file or directory, open '/private/tmp/11ty-cache-asset-slug/.cache/eleventy-cache-assets-@11ty/eleventy.json'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `eleventy`
npm ERR! Exit status 1
Workaround
I had to slugify the key name:
- const asset = new AssetCache("@11ty/eleventy");+ const slugFn = require("@11ty/eleventy/src/Filters/Slug");+ const name = slugFn("@11ty/eleventy");+ const asset = new AssetCache(name);
Now eleventy-cache-assets will save the filename as "./.cache/[email protected]" instead of "./.cache/eleventy-cache-assets-@11ty/eleventy.json"
The text was updated successfully, but these errors were encountered:
I was trying to cache some semi-expensive network calls to npm APIs and noticed I get errors if I set the cache key to something with a "/" in it (like a scoped package name). It looks like eleventy-cache-assets/AssetCache is treating the backslash as a file path delimiter when saving the file, which them blows up since there presumably isn't an ".cache/eleventy-cache-assets-@11ty/" folder.
OUTPUT
Workaround
I had to slugify the key name:
Now eleventy-cache-assets will save the filename as "./.cache/[email protected]" instead of "./.cache/eleventy-cache-assets-@11ty/eleventy.json"
The text was updated successfully, but these errors were encountered: