CSR Cache & Next.js
The browser cache is used with Core's createCsrCache, and /next's callApiSsrCache is added only when Next.js server Data Cache is needed.
The cache wrapper is also part of commonService.
The callApiClientCache/callApiServerCache code on this page explains only the cache part of the project-wide HTTP adapter. Since the generated service can be configured to import this function, it is clearer to first look at the overall structure of rxjsHttpService.ts/commonService.ts to understand the position and role of each wrapper.
CSR Cache (Client Cache)
createCsrCache<CacheName>()provides callApiCsrCache(callApiFn, serviceArgs, cacheOptions) and removeCsrCache(cacheName).
In the server environment, it calls the original callApi without creating a CSR cache map. In the browser, it shares the Observable results of the same cache key using shareReplay.
Next.js Adapter: callApiSsrCache
This is an SSR helper that uses Next.js's next/cache (unstable_cache). If it's a GET request and cacheTime > 0, it uses force-cache + revalidate; otherwise, it executes with no-store.
- You can inject per-request Cookie/Authorization using headersProvider.
- If onServer401 exists at 401, it will be executed.
Do not cache user-specific data.
When bundling browser/server into a single project wrapper
In the shared service, the browser can branch to createCsrCache, and the server can branch to callApiSsrCache. This is a project configuration pattern and not a required structure of Core itself.
commonService.ts
tscommonService.ts
tsWhen using the cache wrapper in the auto-generated service, connect this wrapper only to endpoints that need cache functionality, while using the regular callApi for the rest.