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

[cache] Optionally return stable proxies #47

Open
hjdivad opened this issue Nov 2, 2022 · 2 comments
Open

[cache] Optionally return stable proxies #47

hjdivad opened this issue Nov 2, 2022 · 2 comments

Comments

@hjdivad
Copy link
Contributor

hjdivad commented Nov 2, 2022

Note
It is not clearr whether this is necessary or not.

The high-order-bit is to ensure that cache + third party runtime (e.g.
apollo) makes it easy to interact with the right merged value, when the
merged value changes due to e.g. another request.

The cache returns merged entities from tx.merge(...args). These entities are not naturally going to be referentially stable, e.g. if users specify merge strategies like

async function shallowMergeStrategy<CacheKeyRegistry>(id, { entity, revision }, current: CacheKeyValue | undefined, tx: CacheTransaction<CacheKeyRegistry>) {
  // Object.assign to new object
  return Object.assign({}, current, entity);
}

This won't matter when using Athena, since Athena needs to wrap all access in Proxys anyway in order to support field masking.

However, when using the cache with other runtime systems (e.g. apollo), it may be useful to return something referentially stable to avoid user errors where they interact with older merged objects and forget to call cache.get in e.g. component hooks.

@hjdivad
Copy link
Contributor Author

hjdivad commented Nov 2, 2022

It may be that we don't have a choice and have to make the tx.merge return values referentially stable in order to make athena's DocumentProxy actually strongly reference the cache entries (and thus prevent them from being GC'd).

After all, merge is not only called after tx.commit() it will also be called later, in subsequent requests.

@hjdivad
Copy link
Contributor Author

hjdivad commented Jan 23, 2023

TODO write up more detailed notes

  • cache doesn't need to return stable objects
  • cache only needs to tell the reactivity layer what has changed; that hook is tx.commit
  • tx.commit will want a "after commit" promise

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