Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom filename for AssetCache #49

Merged
merged 1 commit into from
Oct 22, 2024

Conversation

chriskirknielsen
Copy link
Contributor

This fixes #24, allowing custom filenames for AssetCache via a callback function taking the key and hash as arguments.

Usage:

const cachedApiData = new AssetCache('my-wonderful-api', '.cache', { hashLength: 8, cacheFilename: (key, hash) => `11tycache-${key}-${hash}` });

Might be interesting to explore this to hash the contents instead so the filename is more unique but I think this should cover base cases at the very least.

Additionally, lines 25–27 might be overzealous and could likely be discarded, since the getter does check for length meaning we'd fall back to the default filename. Please edit to your heart's content!

@zachleat zachleat added this to the Eleventy Fetch v5.0.0 milestone Oct 22, 2024
@zachleat zachleat merged commit 111c400 into 11ty:master Oct 22, 2024
@zachleat
Copy link
Member

Merged, thank you! Though we’ll probably rename the option filenameFormat to match the Image utility convention

@zachleat zachleat added the enhancement New feature or request label Oct 22, 2024
zachleat added a commit that referenced this pull request Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Human readable cache file names
2 participants