Do gRPC clients have any caching functionality?

2.5k Views Asked by At

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

There are 2 best solutions below

2
On

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.

0
On

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