Do gRPC clients have any caching functionality, e.g. like GraphQL clients have? Without having tried gRPC yet, that's currently the only thing that would keep me from doing tihs.
2 Answers
In issue #7945 there is extensive discussion of support for client caching.
Java's support involves marking a method as safe, which will then cause GET rather than PUT to be used at the HTTP layer. You create an interceptor to implement the caching.
You can see an example of doing caching through your own interceptor at https://github.com/grpc/grpc-java/tree/master/examples/android/clientcache.
Internally, LRS and XDS clients do caching which could also be used as examples.

- 109
- 5
-
first of all, thanks for your reply. I am just confused I can't find any information by googling. Can you please give details which client implemementation you are referring to? (Android, iOs...) – stefan.at.kotlin Mar 08 '23 at 13:51
-
In [issue 7945](https://github.com/grpc/grpc/issues/7945) it was stated that java and C supported client caching, but the support is for marking a method as safe and then using GET rather than put. It is not actually a simple matter of passing a a cache somewhere, but rather you need to create an interceptor. You can see an example of doing caching through your own interceptor at https://github.com/grpc/grpc-java/tree/master/examples/android/clientcache. Internally LRS and XDS clients do caching. I will update my answer to reflect this. – Larry Safran Mar 10 '23 at 18:43
gRPC clients can have caching functionality similar to GraphQL clients. While gRPC does not have built-in caching, you can use third-party libraries or write custom code to implement caching on the client side. One popular library for implementing caching in gRPC clients is "grpc-ecosystem/go-grpc-middleware". Alternatively, you can write your own caching mechanism by creating a custom gRPC client interceptor that intercepts gRPC calls and caches the response

- 21
- 5