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

enableDiskCache 缓存命中问题 #83

Open
zhugazi opened this issue Nov 14, 2023 · 1 comment
Open

enableDiskCache 缓存命中问题 #83

zhugazi opened this issue Nov 14, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@zhugazi
Copy link

zhugazi commented Nov 14, 2023

当我开启了硬盘缓存,可是我还加了一个元数据获取失败兜底函数,这个时候只会走硬盘缓存逻辑,兜底函数不生效了

const obj = {
    enableDiskCache: true,
    apiPrefix: item.apiPrefix,
    versionId: item.version,
    hook: {
        beforeAppendAssetNode(passCtx) {
            const { url, setAssetUrl } = passCtx;
            const jsdelivrUrl = url.replace('https://unpkg.com', item.apiPrefix);
            setAssetUrl(jsdelivrUrl);
        },
        onFetchMetaFailed(params) {
            // 返回一份前端预设的元数据对象,用于兜底
            console.log('开始走兜底逻辑', params);
            console.log('备用cdn数据', _DATA);
            return _DATA;
        },
    },
};
try {
    const helMicro = await import('hel-micro');
    SDK = await helMicro.preFetchLib(item.sdk, obj);
} catch (e) {
    console.log('捕获到异常错误', e);
}
@fantasticsoul fantasticsoul added the enhancement New feature or request label Nov 14, 2023
@fantasticsoul
Copy link
Collaborator

fantasticsoul commented Nov 15, 2023

会优化为,开启硬盘缓存功能后,如果抓取失败后,

1 有硬盘缓存,无 onFetchMetaFailed 钩子,则使用硬盘缓存
2 有硬盘缓存,有 onFetchMetaFailed 钩子,则透传硬盘缓存对象给钩子做参考
    2.1,钩子无任何返回则继续使用硬盘缓存
    2.2,钩子有具体的返回元数据则采用用户的元数据

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

No branches or pull requests

2 participants