Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I populate SSR cache into the QueryResponseCache directly? #5

Open
dehypnosis opened this issue May 23, 2018 · 2 comments
Open

Comments

@dehypnosis
Copy link

dehypnosis commented May 23, 2018

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?

@dehypnosis dehypnosis changed the title Cannot populate ssr cache into the QueryResponseCache, not the ssrMiddleware's cache map? Can I populate SSR cache into the QueryResponseCache directly? May 23, 2018
@dehypnosis
Copy link
Author

dehypnosis commented May 23, 2018

I just make simple onInit hook to your cacheMiddleware which implements SSR caching like below. Will it cause any unexpected problem?

where create relay network interface

// ... 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;
          }
        },
      }),
// ...

where serve entry html

...
<script>window.__API_CACHE__=${JSON.stringify(extractCache())};</script>
...

@nodkz
Copy link
Collaborator

nodkz commented May 23, 2018

It just should work. I don't see any cases where it will not work or occur errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants