Home > front end >  What is a diff between Cache (Normalized, HTTP) and Persisted queries (Apollo)?
What is a diff between Cache (Normalized, HTTP) and Persisted queries (Apollo)?

Time:11-22

An android app uses GraphQL (Apollo), this app has a Normalized cache, in order to reduce the number of queries to the backend.

However, I see there is also APQ (Automatic Persisted Queries), as far as I understand it is also a kind of alternative for cache implementation, but on the backend. right?

So, as far as I understand if the app has both APQ and Normalized cache a query flow looks like this:

query -> check locally in cache -> if nothing -> send query on server -> if there is nothing in APQ -> execute query and send back to the client -> result saves in APQ -> client receives the response -> save response in normalized cache

The question is - does it make sense? Doesn't it look like overkill? I mean what is a reason to make an implementation for both Normalized cache and APQ?

CodePudding user response:

They do different things. A client side cache reduces queries to the server from your device, eliminating their network traffic and resource usage. A server side cache does nothing for network traffic (you must make a request and return a result), but eliminates the resource usage of the query across multiple devices. This means if 1000 people need to make a query, the server only needs to execute it once. The two techniques work together well- the local cache saves more, but the server side cache is more broadly applicable.

  • Related