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

ref(cache): use Map instead of object to store JSMol cache #43

Closed
wants to merge 1 commit into from

Conversation

RamziWeslati
Copy link
Collaborator

Closes #27

try {
mol.delete();
delete globalThis.rdkitWorkerGlobals.jsMolCache[smiles];
globalThis.rdkitWorkerGlobals.jsMolCache.delete(smiles);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  • TODO: use Map.clear at the end of the loop, instead of n calls to delete

Copy link
Contributor

@atfera atfera Apr 3, 2023

Choose a reason for hiding this comment

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

I thought about something like this:

class MolCache extends Map {
  set(smiles) {
    this.set(smiles, rdkit.get_mol(smiles))
  }
  
  delete(k) {
    this.get(k).delete() // delete rdkit mol
    this.delete(k)
  }
  clear() {
    this.forEach((v, k) => {
      v.delete();
      this.delete(k); 
    )}
  }
}

// MolCache
cache.set('C')
cache.clear() //

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

looks good, I'll do that

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

Successfully merging this pull request may close these issues.

Use Map instead of Object for caching
2 participants