Closed as not planned
Description
Is there any plan to support object serialization in cache()
function similar to how modern data fetching libraries handle caching?
Current Behavior
Currently, React's caching mechanism supports only primitive values. This limitation becomes inconvenient when handling multiple properties, necessitating a workaround to manually serialize objects.
React Cache uses a WeakMap
to compare object references, requiring the same object reference to utilize caching effectively.
In previous cache implementations, it was possible to pass a function that serializes keys into strings. Is there any plan to readopt this approach?
Examples from Other Libraries
- SWR: Since SWR 1.1.0, object-like keys will be serialized under the hood automatically.
- TanStack Query: Allows for object keys and provides an option to pass a custom serialization function for unsupported types, making it adaptable for various data fetching scenarios.
Looking forward to your thoughts!