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

@reatom/persist-web-storage garbage collection and asynchronous persistence initialization #753

Open
osovv opened this issue Feb 1, 2024 · 0 comments
Assignees

Comments

@osovv
Copy link
Contributor

osovv commented Feb 1, 2024

We want to:

  1. Collect obsolete persistence as soon as possible, which is currently impossible because accessing a persisted record can only be done with the relative atom.
  2. Initialize asynchronous storage (IndexedDB) at application startup.

Main idea:

Persisted Atoms Registry

  • It would be nice to have a separate registry with metadata about persisted atoms, so that we can manage them based on their lifetime (delete if it has expired).
  • This would be an atom with a PersistRecord array that would also be persisted.
  • We will have some init method (or maybe just on app init) that does the following:
    • Loads the registry into memory from the persistence layer
    • Checks all the entries in the registry:
      • if the entry has expired - it should be deleted (gargabe collector).
      • if the entry has not expired - it should be loaded into the memory cache.
    • We can store the loaded status for each individual persisted atom, or maybe for the whole registry, this is negotiable.

As a result, we can do something like this when initializing the application.

await withIndexedDb.init(ctx)
// or
await withAsyncLocalStorage.init(ctx)

This way, persisted atoms are guaranteed to be initialized during rendering.

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