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

Local cache of text() and arrayBuffer() #57

Open
lpatiny opened this issue Nov 11, 2022 · 0 comments
Open

Local cache of text() and arrayBuffer() #57

lpatiny opened this issue Nov 11, 2022 · 0 comments

Comments

@lpatiny
Copy link
Member

lpatiny commented Nov 11, 2022

Currently each time we call the async function text() or arrayBuffer() the data are reloaded (refetch if it is coming from a web server).

We could therefore have an internal cache system.

One way would be to create a class CachedFileCollectionItem that is wrapping FileCollectionItem.

At first CachedFileCollectionItem would exactly contain the same properties / methods as FileCollectionItem. However we would change the method once the data has been fetched.

class CachedFileCollectionItem {
  constructor(fileCollectionItem) {
    this.fileCollectionItem = fileCollectionItem;
  }
  async text() {
    return this.textCache = this.textCache || this.fileCollectionItem.text();
  }
  async arrayBuffer() {
    return this.arrayBufferCache = this.arrayBufferCache || this.fileCollectionItem.arrayBufferCache();
  }
  async stream() {
    return this.fileCollectionItem.stream(); // no cache for stream !
  }
  get lastModified() {return this.fileCollectionItem.lastModified};
  get name() {return this.fileCollectionItem.name};
  get relativePath() {return this.fileCollectionItem.relativePath};
  get size() {return this.fileCollectionItem.size};

}

The files in FileCollection would therefore become an array of CachedFileCollectionItem
readonly files: CachedFileCollectionItem[];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant