Cache metrics like hit to miss ratio, used space, total size

To effectively tune the data cache, I’m looking for metrics such as the hit-to-miss ratio, used space, and total cache size. Additionally, I’m interested in the amount of memory and disk space allocated for the cache, as it’s important to ensure that these fit within Kubernetes (K8S) limits.

Thanks!

cache_data_api can have some useful information

from streamlit.runtime.caching import cache_data_api

For example, to get the size of cache entries, you can do something like:

sum(
        f.storage._mem_cache.currsize
        for cache in cache_data_api._data_caches
        for f in cache._function_caches.values()
)

Thanks for reply. In the meantime I discovered existing endpoint “/_stcore/metrics”, it exposes exactly what I asked for :slight_smile:

See registered stats providers in the Runtime class:

1 Like

Ah, I didn’t know of this.
@snehankekre , any plans for making this public?

I’ve advocated for documenting some of these endpoints and I believe there is some interest, but I don’t have an ETA on when. It needs a little design pass before it’s publicized in docs, if I recall correctly.