0
0
mirror of https://github.com/django/django.git synced 2024-12-01 15:42:04 +01:00

Used dict comprehensions in BaseMemcachedCache.get_many() and set_many() for better readability.

This commit is contained in:
Sergey Fedoseev 2017-09-05 18:14:41 +05:00 committed by Tim Graham
parent 179b247e07
commit 3633c2a045

View File

@ -89,11 +89,8 @@ class BaseMemcachedCache(BaseCache):
new_keys = [self.make_key(x, version=version) for x in keys]
ret = self._cache.get_multi(new_keys)
if ret:
_ = {}
m = dict(zip(new_keys, keys))
for k, v in ret.items():
_[m[k]] = v
ret = _
return {m[k]: v for k, v in ret.items()}
return ret
def close(self, **kwargs):
@ -137,10 +134,10 @@ class BaseMemcachedCache(BaseCache):
return val
def set_many(self, data, timeout=DEFAULT_TIMEOUT, version=None):
safe_data = {}
for key, value in data.items():
key = self.make_key(key, version=version)
safe_data[key] = value
safe_data = {
self.make_key(key, version=version): value
for key, value in data.items()
}
self._cache.set_multi(safe_data, self.get_backend_timeout(timeout))
def delete_many(self, keys, version=None):