Skip to content
New issue

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

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

Already on GitHub? # to your account

[Web][PROPOSAL]: implement ArtifactCache using OPFS #17510

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

KarolNov
Copy link

@KarolNov KarolNov commented Nov 10, 2024

Motivation
OPFS has better persistence, performance, and consistent support for large files across browsers.
Personally I would like to see this caching strategy for https://github.com/mlc-ai/web-llm.

This PR doesn't implement all required changes and hasn't been proved to work yet - I just created a PoC class implementing the ArtifactCacheTemplate.
Potentially a problem with this approach would be that this cache uses OPFS on main thread with async APIs. A better solution could be to use Web Worker and sync file handlers - https://developer.mozilla.org/en-US/docs/Web/API/File_System_API/Origin_private_file_system#manipulating_the_opfs_from_a_web_worker. Both approaches could be valid for different use cases, so I propose creating 2 new caching strategies - opfs and opfs-worker.
I could finish the required work if we find it useful. Otherwise I would just move caching higher up in my stack and just do it for my specific use case.


constructor(dirName: string) {
// use the version suffix to allow upgrade if needed
this.dirName = `${dirName}-v${this.fileVersion}`;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm new to this repo, but it seems versioning is not really needed here and it's up for user to version the urls instead. However storing the -vX suffix would allow to do internal breaking changes in the file structure by just creating a new OPFS cache handler that uses different dir name -v2.

@KarolNov KarolNov changed the title [PROPOSAL]: implement ArtifactCache using OPFS [Web][PROPOSAL]: implement ArtifactCache using OPFS Nov 10, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant