Guest User

Untitled

a guest
Jul 22nd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. const relayResponseCache = new RelayQueryResponseCache({ size: 250, ttl: oneMinute });
  2.  
  3. const cacheHandler = async (
  4. request: RequestNode,
  5. variables: Variables,
  6. cacheConfig: CacheConfig,
  7. uploadables: UploadableMap,
  8. ) => {
  9. const queryID = request.text;
  10.  
  11. if (isMutation(request)) {
  12. relayResponseCache.clear();
  13. return fetchFunction(request, variables, cacheConfig, uploadables);
  14. }
  15.  
  16. const fromCache = relayResponseCache.get(queryID, variables);
  17.  
  18. if (isQuery(request) && fromCache !== null && !forceFetch(cacheConfig)) {
  19. return fromCache;
  20. }
  21.  
  22. const fromServer = await fetchFunction(request, variables, cacheConfig, uploadables);
  23. if (fromServer) {
  24. relayResponseCache.set(queryID, variables, fromServer);
  25. }
  26.  
  27. return fromServer;
  28. };
Add Comment
Please, Sign In to add comment