report metrics on number of cache evictions

This commit is contained in:
Richard van der Hoff 2018-02-01 17:57:51 +00:00
parent 77c0629ebc
commit bc496df192
5 changed files with 56 additions and 5 deletions

View file

@ -75,6 +75,7 @@ class Cache(object):
self.cache = LruCache(
max_size=max_entries, keylen=keylen, cache_type=cache_type,
size_callback=(lambda d: len(d)) if iterable else None,
evicted_callback=self._on_evicted,
)
self.name = name
@ -83,6 +84,9 @@ class Cache(object):
self.thread = None
self.metrics = register_cache(name, self.cache)
def _on_evicted(self, evicted_count):
self.metrics.inc_evictions(evicted_count)
def check_thread(self):
expected_thread = self.thread
if expected_thread is None: