feat(archive-cache): added extra info on number of evicted caches

This commit is contained in:
RhodeCode Admin 2024-06-14 08:57:51 +02:00
parent 984a9a564f
commit bb46f148f2
3 changed files with 13 additions and 9 deletions

View file

@ -247,7 +247,7 @@ class BaseCache:
def get_lock(self, lock_key):
return GenerationLock(lock_key, self._locking_url)
def evict(self, policy=None, size_limit=None) -> int:
def evict(self, policy=None, size_limit=None) -> dict:
"""
Remove old items based on the conditions
@ -257,13 +257,16 @@ class BaseCache:
read the key files metadata stored. This gives us a full list of keys, cached_archived, their size and
access data, time creation, and access counts.
Store that into a memory DB so we can run different sorting strategies easily.
Store that into a memory DB in order we can run different sorting strategies easily.
Summing the size is a sum sql query.
Then we run a sorting strategy based on eviction policy.
We iterate over sorted keys, and remove each checking if we hit the overall limit.
"""
removal_info = {
"removed_items": 0,
"removed_size": 0
}
policy = policy or self._eviction_policy
size_limit = size_limit or self._cache_size_limit
@ -273,7 +276,7 @@ class BaseCache:
policy, format_size(size_limit))
if select_policy is None:
return 0
return removal_info
db = self.get_stats_db()
@ -327,10 +330,11 @@ class BaseCache:
self.remove(archive_key)
removed_items += 1
removed_size += size
removal_info['removed_items'] = removed_items
removal_info['removed_size'] = removed_size
log.debug('Removed %s cache archives, and reduced size by: %s',
removed_items, format_size(removed_size))
return removed_items
return removal_info
def get_statistics(self):
total_files = 0