Open dehypnosis opened 6 years ago
I just make simple onInit hook to your cacheMiddleware which implements SSR caching like below. Will it cause any unexpected problem?
// ... middlewares
cacheMiddleware({
size: 100, // max 100 requests
ttl: 900000, // 15 minutes,
onInit: cacheMap => {
// rehydrate cache from response script on browser
if (IS_BROWSER) {
const cacheArray = window.__API_CACHE__;
cacheArray.forEach(cacheItem => {
cacheMap._responses.set(cacheItem[0], cacheItem[1]);
});
} else { // export extract function for server
extractCache = () => cacheMap._responses;
}
},
}),
// ...
...
<script>window.__API_CACHE__=${JSON.stringify(extractCache())};</script>
...
It just should work. I don't see any cases where it will not work or occur errors.
This works great. Thanks! But I am somewhat worried about that SSR Middleware's cache has no policy like TTL or size which QueryResponseCache has. And I want to unify them. Can I populate cache into relay environment directly?