Hacker News new | ask | show | jobs
by bunkat 3679 days ago
Has anybody figured out how you do caching and cache invalidation on the client with GraphQL if every page is requesting slightly different forms of the same data? Seems like it is a bigger win to just download the 400 friends once and let the pages use the data they need instead of downloading the 400 friends 10 different ways.

My particular app is read heavy and so I can eliminate the majority of the server calls altogether via caching. While GraphQL would help me fetch only the data I need on each page and decouple the data access, I don't see how I reuse objects across pages without interrogating the GraphQL queries. I haven't given it all that much thought though so maybe I'm missing something.

2 comments

I think is worth to take a look into Facebook's dataloader. Instead of having a caching mechanism (likve Varnish) in your HTTP layer, you could have it in your GraphQL backend.

https://github.com/facebook/dataloader

Great suggestion. We are currently working on getting this setup on our side!
Facebook's Relay.js implements a pretty ingenious caching layer that is designed to work with GraphQL. It might be worth a look (https://facebook.github.io/relay/).