Right now the cache is global, which works well, and even works for when providers change. However, this doesn't make a lot of sense long-term, because it causes unbounded cache growth, and resetting the provider doesn't actually free any memory.
I think there's a couple ways to solve this:
- Cache object is provided by the provider itself. This should help clean up memory when providers are reset / removed.
- Cache is a user-configurable LRU cache, with the ability to explicitly retain data that is actively being used.
- Hooks cause data being used to be explicitly retained (need to figure out how this works with suspense and concurrent).
Right now the cache is global, which works well, and even works for when providers change. However, this doesn't make a lot of sense long-term, because it causes unbounded cache growth, and resetting the provider doesn't actually free any memory.
I think there's a couple ways to solve this: