# HG changeset patch # User RhodeCode Admin # Date 2024-06-14 06:59:27 # Node ID acea161c02eec037d091339b675ea16a10904a88 # Parent f8e66197e96caa7216cc0e834cb79eb8e141a8de archive-cache: synced with ce diff --git a/vcsserver/lib/archive_cache/backends/base.py b/vcsserver/lib/archive_cache/backends/base.py --- a/vcsserver/lib/archive_cache/backends/base.py +++ b/vcsserver/lib/archive_cache/backends/base.py @@ -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