# HG changeset patch # User Marcin Kuzminski # Date 2018-07-13 16:39:52 # Node ID fc338c667db31624f5dd5f74145f6bdb53b9ea61 # Parent 2a9499df9886bc9591db2468efc597180335545e caches: use delete_multi for clearing out cache keys. - This is a safer and more efficient way of purging many keys. - For file based cache it only opens the DB once diff --git a/rhodecode/lib/rc_cache/utils.py b/rhodecode/lib/rc_cache/utils.py --- a/rhodecode/lib/rc_cache/utils.py +++ b/rhodecode/lib/rc_cache/utils.py @@ -102,6 +102,5 @@ def get_or_create_region(region_name, re def clear_cache_namespace(cache_region, cache_namespace_uid): region = get_or_create_region(cache_region, cache_namespace_uid) cache_keys = region.backend.list_keys(prefix=cache_namespace_uid) - for k in cache_keys: - region.delete(k) + region.delete_multi(cache_keys) return len(cache_keys) diff --git a/rhodecode/tests/lib/test_caches.py b/rhodecode/tests/lib/test_caches.py --- a/rhodecode/tests/lib/test_caches.py +++ b/rhodecode/tests/lib/test_caches.py @@ -74,8 +74,7 @@ class TestCaches(object): def test_store_value_in_cache(self): cache_region = rc_cache.get_or_create_region('cache_perms') # make sure we empty the cache now - for key in cache_region.backend.list_keys(): - cache_region.delete(key) + cache_region.delete_multi(cache_region.backend.list_keys()) assert cache_region.backend.list_keys() == []