feat(core): add ability to cache resources for SSR#68226
feat(core): add ability to cache resources for SSR#68226JeanMeche wants to merge 2 commits intoangular:mainfrom
Conversation
| equal?: ValueEqualityFn<T>; | ||
| injector?: Injector; | ||
| params?: (ctx: ResourceParamsContext) => R; | ||
| transferCacheKey?: (params: R) => StateKey<T>; |
There was a problem hiding this comment.
Copyied from a previous PR, @alan-agius4
- Does this implementation result in duplicate transfer state entries (HTTP Client andResource)?
- Consider
idmaybe instead oftransferCacheKey?- Manual key management places a heavy burden on the developer to ensure global uniqueness. To improve the DX, we should explore internal ID generation instead of it being part of the API or something similar to React’s
useIdor Vue’s composition helpers. Relying on users to manual create unique cache-key feels like a "foot-gun" especially in big organizations; we should ideally handle key construction internally to prevent collisions, this was one of the reasons that we always avoided providing such option in the HTTP transfer cache.
There was a problem hiding this comment.
Does this implementation result in duplicate transfer state entries (HTTP Client andResource)?
And rxResource that calls HttpClient wouldn't need to use the cache here (thx to #67382). It they enabled the caching here, it would indeed duplicate the transfer.
I agree that we should provide a util to generate unit Ids.
There was a problem hiding this comment.
I am a bit confused as the this PR is linked to close issue #62897 which uses both rxResource with HttpClient, but you are saying this is already handled.
There was a problem hiding this comment.
We considered that #67382 was broader than just HttpClient + rxResource.
Here we complete the caching feature by providing an option to cache anything (anything that is serializable).
This commit adds a `transferCacheKey` option to enable easy caching for `resource`/ `rxResource`. By caching resource data we make sure that resources are not in a loading state during hydration on the client side and responsible for destroying server hydrated DOM. fixes angular#62897
dab8cc9 to
642433e
Compare
642433e to
d485f4e
Compare
This commit adds a
transferCacheKeyoption to enable easy caching forresource/rxResource.By caching resource data we make sure that resources are not in a loading state during hydration on the client side and responsible for destroying server hydrated DOM.
fixes #62897