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
This commit is contained in:
Marcin Kuzminski 2018-07-13 18:39:52 +02:00
parent f4b8149962
commit ec504c9907
2 changed files with 2 additions and 4 deletions

View file

@ -102,6 +102,5 @@ def get_or_create_region(region_name, region_namespace=None):
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)

View file

@ -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() == []