How do we capture or measure the effectiveness of client-side caching policies using Apollo Client? Is there a way to measure hit rates on the cache?

How do we capture or measure the effectiveness of client-side caching policies using Apollo Client? Is there a way to measure cache hit rates on the cache, and to monitor that over time? How do people out there capture this kind of telemetry or information about the effectiveness of the Apollo Client for client-side caching?

Hi @ronrlin Apollo does have a set of client developer tools that lets you interact with the cache in the browser, you can read about that here, though these dev tools don’t currently measure hit rates of the cache to the level I assume you are looking for.

You might want to also check out our docs on error handling for ideas.

Others in the community might have some more practical advice to share as well.

Hi @ronrlin :wave: While we do not have an officially supported API for logging cache hits, I will direct you to this comment from a relevant GitHub issue: Logging queries which only hit the cache · Issue #87 · apollographql/apollo-feature-requests · GitHub

It mentions the private API __actionHookForDevTools which the Apollo Dev Tools uses to achieve something similar and may help you achieve what you have in mind. If there are ever plans to make an official API, you can follow that issue for updates. Thanks!

1 Like