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

Use a per-documentLoader resolved context cache. #552

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

davidlehn
Copy link
Member

Fixes an issue where multiple document loaders are used which each have different values for static contexts.

A WeakMap is used for caches and is cleaned up using WeakMap semantics based on the lifetime of the documentLoader keys.

@davidlehn davidlehn requested a review from dlongley May 31, 2024 04:29
@davidlehn
Copy link
Member Author

A bit more info for this issue:

  • This depends on a document loader using the (I think undocumented) feature of setting a resolved context result with a tag of "static". That triggers storing in a "shared" cache that is used between calls to the library.
  • If multiple API calls are made using multiple document loaders, and each resolves the same URL to a different value, this can cause an error.
  • This is probably not a common pattern, but can appear in test suites for example.

About this initial fix:

  • Handled at the top level and uses unique shared caches per documentLoader.
  • The cache resources used will scale with the number of document loaders used.
  • The WeakMap usage should hopefully clean up resources depending on how apps document loader lifetimes.
  • Alternative approaches would likely be in ContextResolver and either also keying on a documentLoader, or tracking and checking the loader in the values. This seemed to be pushing the fix a bit far down in the resolver details.

For future work, the entire caching setup should be revisited. Apps should have more control over cache use, size, and duration. There are many ways this could be designed.

Fixes an issue where multiple document loaders are used which each have
different values for static contexts.

A WeakMap is used for caches and is cleaned up using WeakMap semantics
based on the lifetime of the documentLoader keys.
@davidlehn davidlehn marked this pull request as ready for review May 31, 2024 19:48
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.

2 participants