diff --git a/rhodecode/lib/archive_cache/backends/base.py b/rhodecode/lib/archive_cache/backends/base.py --- a/rhodecode/lib/archive_cache/backends/base.py +++ b/rhodecode/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 diff --git a/rhodecode/tests/lib/test_archive_caches.py b/rhodecode/tests/lib/test_archive_caches.py --- a/rhodecode/tests/lib/test_archive_caches.py +++ b/rhodecode/tests/lib/test_archive_caches.py @@ -98,7 +98,7 @@ class TestArchiveCaches(object): evict_to = 0.005 # around (5mb) evicted_items = d_cache.evict(size_limit=d_cache.gb_to_bytes(evict_to)) evicted = 361 - assert evicted == evicted_items + assert {'removed_items': evicted, 'removed_size': 14039290} == evicted_items stats = d_cache.get_statistics() assert (tries - evicted, 5405710, {}) == stats diff --git a/rhodecode/tests/rhodecode.ini b/rhodecode/tests/rhodecode.ini --- a/rhodecode/tests/rhodecode.ini +++ b/rhodecode/tests/rhodecode.ini @@ -348,7 +348,7 @@ celery.task_store_eager_result = true ; Default cache dir for caches. Putting this into a ramdisk can boost performance. ; eg. /tmpfs/data_ramdisk, however this directory might require large amount of space -cache_dir = /var/opt/rhodecode_data +cache_dir = %(here)s/rc-test-data ; ********************************************* ; `sql_cache_short` cache for heavy SQL queries @@ -681,7 +681,7 @@ ssh.wrapper_cmd_allow_shell = false ; Enables logging, and detailed output send back to the client during SSH ; operations. Useful for debugging, shouldn't be used in production. -ssh.enable_debug_logging = false +ssh.enable_debug_logging = true ; Paths to binary executable, by default they are the names, but we can ; override them if we want to use a custom one