You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Previously, controllers of SSR'd sections were responsible for caching API data. But there's a better way: We're already sending Redux state to the client at server-render time, so why not also cache on the server side, and use that as the initial state when creating the Redux store for the next request (given that this is in logged-out mode, i.e. the cache key -- the route -- maps one-to-one to the state, with the exception of errors like 404s, where one error page can be enough for different invalid routes).
Furthermore, this PR removes `renderCacheKey` and just uses `context.pathname` for _markup_ cache. Previously, we were using concatenated path and API data (~state) cache timestamp as key. Creating the markup cache key isn't the section controller's responsibility now.
Copy file name to clipboardExpand all lines: docs/server-side-rendering.md
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,11 +22,13 @@ React components used on the server will be rendered to HTML by being passed to
22
22
23
23
### Caching
24
24
25
-
Because it is necessary to serve the redux state along with a server-rendered page, we use two levels of cache on the server: one to store raw query data, from which we can generate and serve redux state, and one to store rendered layouts.
25
+
Because it is necessary to serve the redux state along with a server-rendered page, we use two levels of cache on the server: one to store the redux state, and one to store rendered layouts.
26
26
27
27
##### Data Cache
28
28
29
-
Caching data is currently left to the controller for a [given](../client/my-sites/themes/controller.jsx)[section](../client/my-sites/theme/controller.jsx). Request timestamps are used to force expiration.
29
+
At render time, the Redux state is [serialized and cached](../server/render/index.js), using the current path as the cache key, unless there is a query string, in which case we don't cache.
30
+
31
+
This means that all data that was fetched to render a given page is available the next time the corresponding route is hit. A section controller thus only needs to check if the required data is available (using selectors), and dispatch the corresponding fetching action if it isn't; see the [themes controller](../client/my-sites/themes/controller.jsx) for an example.
0 commit comments