From 9c19aff7c7561e3a82978a272ecdaad40dda5c00 Mon Sep 17 00:00:00 2001 From: django-bot Date: Thu, 3 Feb 2022 20:24:19 +0100 Subject: Refs #33476 -- Reformatted code with Black. --- django/core/cache/__init__.py | 25 ++++-- django/core/cache/backends/base.py | 64 +++++++++----- django/core/cache/backends/db.py | 145 ++++++++++++++++++-------------- django/core/cache/backends/filebased.py | 28 +++--- django/core/cache/backends/memcached.py | 37 +++++--- django/core/cache/backends/redis.py | 13 +-- django/core/cache/utils.py | 4 +- 7 files changed, 193 insertions(+), 123 deletions(-) (limited to 'django/core/cache') diff --git a/django/core/cache/__init__.py b/django/core/cache/__init__.py index a311b50af6..f09c9ecc4b 100644 --- a/django/core/cache/__init__.py +++ b/django/core/cache/__init__.py @@ -14,27 +14,35 @@ See docs/topics/cache.txt for information on the public API. """ from django.core import signals from django.core.cache.backends.base import ( - BaseCache, CacheKeyWarning, InvalidCacheBackendError, InvalidCacheKey, + BaseCache, + CacheKeyWarning, + InvalidCacheBackendError, + InvalidCacheKey, ) from django.utils.connection import BaseConnectionHandler, ConnectionProxy from django.utils.module_loading import import_string __all__ = [ - 'cache', 'caches', 'DEFAULT_CACHE_ALIAS', 'InvalidCacheBackendError', - 'CacheKeyWarning', 'BaseCache', 'InvalidCacheKey', + "cache", + "caches", + "DEFAULT_CACHE_ALIAS", + "InvalidCacheBackendError", + "CacheKeyWarning", + "BaseCache", + "InvalidCacheKey", ] -DEFAULT_CACHE_ALIAS = 'default' +DEFAULT_CACHE_ALIAS = "default" class CacheHandler(BaseConnectionHandler): - settings_name = 'CACHES' + settings_name = "CACHES" exception_class = InvalidCacheBackendError def create_connection(self, alias): params = self.settings[alias].copy() - backend = params.pop('BACKEND') - location = params.pop('LOCATION', '') + backend = params.pop("BACKEND") + location = params.pop("LOCATION", "") try: backend_cls = import_string(backend) except ImportError as e: @@ -45,7 +53,8 @@ class CacheHandler(BaseConnectionHandler): def all(self, initialized_only=False): return [ - self[alias] for alias in self + self[alias] + for alias in self # If initialized_only is True, return only initialized caches. if not initialized_only or hasattr(self._connections, alias) ] diff --git a/django/core/cache/backends/base.py b/django/core/cache/backends/base.py index f632d851ea..eb4b3eac6d 100644 --- a/django/core/cache/backends/base.py +++ b/django/core/cache/backends/base.py @@ -36,7 +36,7 @@ def default_key_func(key, key_prefix, version): the `key_prefix`. KEY_FUNCTION can be used to specify an alternate function with custom key making behavior. """ - return '%s:%s:%s' % (key_prefix, version, key) + return "%s:%s:%s" % (key_prefix, version, key) def get_key_func(key_func): @@ -57,7 +57,7 @@ class BaseCache: _missing_key = object() def __init__(self, params): - timeout = params.get('timeout', params.get('TIMEOUT', 300)) + timeout = params.get("timeout", params.get("TIMEOUT", 300)) if timeout is not None: try: timeout = int(timeout) @@ -65,22 +65,22 @@ class BaseCache: timeout = 300 self.default_timeout = timeout - options = params.get('OPTIONS', {}) - max_entries = params.get('max_entries', options.get('MAX_ENTRIES', 300)) + options = params.get("OPTIONS", {}) + max_entries = params.get("max_entries", options.get("MAX_ENTRIES", 300)) try: self._max_entries = int(max_entries) except (ValueError, TypeError): self._max_entries = 300 - cull_frequency = params.get('cull_frequency', options.get('CULL_FREQUENCY', 3)) + cull_frequency = params.get("cull_frequency", options.get("CULL_FREQUENCY", 3)) try: self._cull_frequency = int(cull_frequency) except (ValueError, TypeError): self._cull_frequency = 3 - self.key_prefix = params.get('KEY_PREFIX', '') - self.version = params.get('VERSION', 1) - self.key_func = get_key_func(params.get('KEY_FUNCTION')) + self.key_prefix = params.get("KEY_PREFIX", "") + self.version = params.get("VERSION", 1) + self.key_func = get_key_func(params.get("KEY_FUNCTION")) def get_backend_timeout(self, timeout=DEFAULT_TIMEOUT): """ @@ -130,47 +130,61 @@ class BaseCache: Return True if the value was stored, False otherwise. """ - raise NotImplementedError('subclasses of BaseCache must provide an add() method') + raise NotImplementedError( + "subclasses of BaseCache must provide an add() method" + ) async def aadd(self, key, value, timeout=DEFAULT_TIMEOUT, version=None): - return await sync_to_async(self.add, thread_sensitive=True)(key, value, timeout, version) + return await sync_to_async(self.add, thread_sensitive=True)( + key, value, timeout, version + ) def get(self, key, default=None, version=None): """ Fetch a given key from the cache. If the key does not exist, return default, which itself defaults to None. """ - raise NotImplementedError('subclasses of BaseCache must provide a get() method') + raise NotImplementedError("subclasses of BaseCache must provide a get() method") async def aget(self, key, default=None, version=None): - return await sync_to_async(self.get, thread_sensitive=True)(key, default, version) + return await sync_to_async(self.get, thread_sensitive=True)( + key, default, version + ) def set(self, key, value, timeout=DEFAULT_TIMEOUT, version=None): """ Set a value in the cache. If timeout is given, use that timeout for the key; otherwise use the default cache timeout. """ - raise NotImplementedError('subclasses of BaseCache must provide a set() method') + raise NotImplementedError("subclasses of BaseCache must provide a set() method") async def aset(self, key, value, timeout=DEFAULT_TIMEOUT, version=None): - return await sync_to_async(self.set, thread_sensitive=True)(key, value, timeout, version) + return await sync_to_async(self.set, thread_sensitive=True)( + key, value, timeout, version + ) def touch(self, key, timeout=DEFAULT_TIMEOUT, version=None): """ Update the key's expiry time using timeout. Return True if successful or False if the key does not exist. """ - raise NotImplementedError('subclasses of BaseCache must provide a touch() method') + raise NotImplementedError( + "subclasses of BaseCache must provide a touch() method" + ) async def atouch(self, key, timeout=DEFAULT_TIMEOUT, version=None): - return await sync_to_async(self.touch, thread_sensitive=True)(key, timeout, version) + return await sync_to_async(self.touch, thread_sensitive=True)( + key, timeout, version + ) def delete(self, key, version=None): """ Delete a key from the cache and return whether it succeeded, failing silently. """ - raise NotImplementedError('subclasses of BaseCache must provide a delete() method') + raise NotImplementedError( + "subclasses of BaseCache must provide a delete() method" + ) async def adelete(self, key, version=None): return await sync_to_async(self.delete, thread_sensitive=True)(key, version) @@ -234,7 +248,9 @@ class BaseCache: """ Return True if the key is in the cache and has not expired. """ - return self.get(key, self._missing_key, version=version) is not self._missing_key + return ( + self.get(key, self._missing_key, version=version) is not self._missing_key + ) async def ahas_key(self, key, version=None): return ( @@ -318,7 +334,9 @@ class BaseCache: def clear(self): """Remove *all* values from the cache at once.""" - raise NotImplementedError('subclasses of BaseCache must provide a clear() method') + raise NotImplementedError( + "subclasses of BaseCache must provide a clear() method" + ) async def aclear(self): return await sync_to_async(self.clear, thread_sensitive=True)() @@ -373,13 +391,13 @@ class BaseCache: def memcache_key_warnings(key): if len(key) > MEMCACHE_MAX_KEY_LENGTH: yield ( - 'Cache key will cause errors if used with memcached: %r ' - '(longer than %s)' % (key, MEMCACHE_MAX_KEY_LENGTH) + "Cache key will cause errors if used with memcached: %r " + "(longer than %s)" % (key, MEMCACHE_MAX_KEY_LENGTH) ) for char in key: if ord(char) < 33 or ord(char) == 127: yield ( - 'Cache key contains characters that will cause errors if ' - 'used with memcached: %r' % key + "Cache key contains characters that will cause errors if " + "used with memcached: %r" % key ) break diff --git a/django/core/cache/backends/db.py b/django/core/cache/backends/db.py index 5bb1c5aec5..e3d055084c 100644 --- a/django/core/cache/backends/db.py +++ b/django/core/cache/backends/db.py @@ -14,13 +14,14 @@ class Options: This allows cache operations to be controlled by the router """ + def __init__(self, table): self.db_table = table - self.app_label = 'django_cache' - self.model_name = 'cacheentry' - self.verbose_name = 'cache entry' - self.verbose_name_plural = 'cache entries' - self.object_name = 'CacheEntry' + self.app_label = "django_cache" + self.model_name = "cacheentry" + self.verbose_name = "cache entry" + self.verbose_name_plural = "cache entries" + self.object_name = "CacheEntry" self.abstract = False self.managed = True self.proxy = False @@ -34,6 +35,7 @@ class BaseDatabaseCache(BaseCache): class CacheEntry: _meta = Options(table) + self.cache_model_class = CacheEntry @@ -54,7 +56,9 @@ class DatabaseCache(BaseDatabaseCache): if not keys: return {} - key_map = {self.make_and_validate_key(key, version=version): key for key in keys} + key_map = { + self.make_and_validate_key(key, version=version): key for key in keys + } db = router.db_for_read(self.cache_model_class) connection = connections[db] @@ -63,13 +67,14 @@ class DatabaseCache(BaseDatabaseCache): with connection.cursor() as cursor: cursor.execute( - 'SELECT %s, %s, %s FROM %s WHERE %s IN (%s)' % ( - quote_name('cache_key'), - quote_name('value'), - quote_name('expires'), + "SELECT %s, %s, %s FROM %s WHERE %s IN (%s)" + % ( + quote_name("cache_key"), + quote_name("value"), + quote_name("expires"), table, - quote_name('cache_key'), - ', '.join(['%s'] * len(key_map)), + quote_name("cache_key"), + ", ".join(["%s"] * len(key_map)), ), list(key_map), ) @@ -78,7 +83,9 @@ class DatabaseCache(BaseDatabaseCache): result = {} expired_keys = [] expression = models.Expression(output_field=models.DateTimeField()) - converters = (connection.ops.get_db_converters(expression) + expression.get_db_converters(connection)) + converters = connection.ops.get_db_converters( + expression + ) + expression.get_db_converters(connection) for key, value, expires in rows: for converter in converters: expires = converter(expires, expression, connection) @@ -93,15 +100,15 @@ class DatabaseCache(BaseDatabaseCache): def set(self, key, value, timeout=DEFAULT_TIMEOUT, version=None): key = self.make_and_validate_key(key, version=version) - self._base_set('set', key, value, timeout) + self._base_set("set", key, value, timeout) def add(self, key, value, timeout=DEFAULT_TIMEOUT, version=None): key = self.make_and_validate_key(key, version=version) - return self._base_set('add', key, value, timeout) + return self._base_set("add", key, value, timeout) def touch(self, key, timeout=DEFAULT_TIMEOUT, version=None): key = self.make_and_validate_key(key, version=version) - return self._base_set('touch', key, None, timeout) + return self._base_set("touch", key, None, timeout) def _base_set(self, mode, key, value, timeout=DEFAULT_TIMEOUT): timeout = self.get_backend_timeout(timeout) @@ -126,7 +133,7 @@ class DatabaseCache(BaseDatabaseCache): pickled = pickle.dumps(value, self.pickle_protocol) # The DB column is expecting a string, so make sure the value is a # string, not bytes. Refs #19274. - b64encoded = base64.b64encode(pickled).decode('latin1') + b64encoded = base64.b64encode(pickled).decode("latin1") try: # Note: typecasting for datetimes is needed by some 3rd party # database backends. All core backends work without typecasting, @@ -134,52 +141,59 @@ class DatabaseCache(BaseDatabaseCache): # regressions. with transaction.atomic(using=db): cursor.execute( - 'SELECT %s, %s FROM %s WHERE %s = %%s' % ( - quote_name('cache_key'), - quote_name('expires'), + "SELECT %s, %s FROM %s WHERE %s = %%s" + % ( + quote_name("cache_key"), + quote_name("expires"), table, - quote_name('cache_key'), + quote_name("cache_key"), ), - [key] + [key], ) result = cursor.fetchone() if result: current_expires = result[1] - expression = models.Expression(output_field=models.DateTimeField()) - for converter in (connection.ops.get_db_converters(expression) + - expression.get_db_converters(connection)): - current_expires = converter(current_expires, expression, connection) + expression = models.Expression( + output_field=models.DateTimeField() + ) + for converter in connection.ops.get_db_converters( + expression + ) + expression.get_db_converters(connection): + current_expires = converter( + current_expires, expression, connection + ) exp = connection.ops.adapt_datetimefield_value(exp) - if result and mode == 'touch': + if result and mode == "touch": cursor.execute( - 'UPDATE %s SET %s = %%s WHERE %s = %%s' % ( - table, - quote_name('expires'), - quote_name('cache_key') - ), - [exp, key] + "UPDATE %s SET %s = %%s WHERE %s = %%s" + % (table, quote_name("expires"), quote_name("cache_key")), + [exp, key], ) - elif result and (mode == 'set' or (mode == 'add' and current_expires < now)): + elif result and ( + mode == "set" or (mode == "add" and current_expires < now) + ): cursor.execute( - 'UPDATE %s SET %s = %%s, %s = %%s WHERE %s = %%s' % ( + "UPDATE %s SET %s = %%s, %s = %%s WHERE %s = %%s" + % ( table, - quote_name('value'), - quote_name('expires'), - quote_name('cache_key'), + quote_name("value"), + quote_name("expires"), + quote_name("cache_key"), ), - [b64encoded, exp, key] + [b64encoded, exp, key], ) - elif mode != 'touch': + elif mode != "touch": cursor.execute( - 'INSERT INTO %s (%s, %s, %s) VALUES (%%s, %%s, %%s)' % ( + "INSERT INTO %s (%s, %s, %s) VALUES (%%s, %%s, %%s)" + % ( table, - quote_name('cache_key'), - quote_name('value'), - quote_name('expires'), + quote_name("cache_key"), + quote_name("value"), + quote_name("expires"), ), - [key, b64encoded, exp] + [key, b64encoded, exp], ) else: return False # touch failed. @@ -208,10 +222,11 @@ class DatabaseCache(BaseDatabaseCache): with connection.cursor() as cursor: cursor.execute( - 'DELETE FROM %s WHERE %s IN (%s)' % ( + "DELETE FROM %s WHERE %s IN (%s)" + % ( table, - quote_name('cache_key'), - ', '.join(['%s'] * len(keys)), + quote_name("cache_key"), + ", ".join(["%s"] * len(keys)), ), keys, ) @@ -228,13 +243,14 @@ class DatabaseCache(BaseDatabaseCache): with connection.cursor() as cursor: cursor.execute( - 'SELECT %s FROM %s WHERE %s = %%s and %s > %%s' % ( - quote_name('cache_key'), + "SELECT %s FROM %s WHERE %s = %%s and %s > %%s" + % ( + quote_name("cache_key"), quote_name(self._table), - quote_name('cache_key'), - quote_name('expires'), + quote_name("cache_key"), + quote_name("expires"), ), - [key, connection.ops.adapt_datetimefield_value(now)] + [key, connection.ops.adapt_datetimefield_value(now)], ) return cursor.fetchone() is not None @@ -244,23 +260,28 @@ class DatabaseCache(BaseDatabaseCache): else: connection = connections[db] table = connection.ops.quote_name(self._table) - cursor.execute('DELETE FROM %s WHERE %s < %%s' % ( - table, - connection.ops.quote_name('expires'), - ), [connection.ops.adapt_datetimefield_value(now)]) + cursor.execute( + "DELETE FROM %s WHERE %s < %%s" + % ( + table, + connection.ops.quote_name("expires"), + ), + [connection.ops.adapt_datetimefield_value(now)], + ) deleted_count = cursor.rowcount remaining_num = num - deleted_count if remaining_num > self._max_entries: cull_num = remaining_num // self._cull_frequency cursor.execute( - connection.ops.cache_key_culling_sql() % table, - [cull_num]) + connection.ops.cache_key_culling_sql() % table, [cull_num] + ) last_cache_key = cursor.fetchone() if last_cache_key: cursor.execute( - 'DELETE FROM %s WHERE %s < %%s' % ( + "DELETE FROM %s WHERE %s < %%s" + % ( table, - connection.ops.quote_name('cache_key'), + connection.ops.quote_name("cache_key"), ), [last_cache_key[0]], ) @@ -270,4 +291,4 @@ class DatabaseCache(BaseDatabaseCache): connection = connections[db] table = connection.ops.quote_name(self._table) with connection.cursor() as cursor: - cursor.execute('DELETE FROM %s' % table) + cursor.execute("DELETE FROM %s" % table) diff --git a/django/core/cache/backends/filebased.py b/django/core/cache/backends/filebased.py index fc99d11687..631da49444 100644 --- a/django/core/cache/backends/filebased.py +++ b/django/core/cache/backends/filebased.py @@ -14,7 +14,7 @@ from django.utils.crypto import md5 class FileBasedCache(BaseCache): - cache_suffix = '.djcache' + cache_suffix = ".djcache" pickle_protocol = pickle.HIGHEST_PROTOCOL def __init__(self, dir, params): @@ -31,7 +31,7 @@ class FileBasedCache(BaseCache): def get(self, key, default=None, version=None): fname = self._key_to_file(key, version) try: - with open(fname, 'rb') as f: + with open(fname, "rb") as f: if not self._is_expired(f): return pickle.loads(zlib.decompress(f.read())) except FileNotFoundError: @@ -50,7 +50,7 @@ class FileBasedCache(BaseCache): fd, tmp_path = tempfile.mkstemp(dir=self._dir) renamed = False try: - with open(fd, 'wb') as f: + with open(fd, "wb") as f: self._write_content(f, timeout, value) file_move_safe(tmp_path, fname, allow_overwrite=True) renamed = True @@ -60,7 +60,7 @@ class FileBasedCache(BaseCache): def touch(self, key, timeout=DEFAULT_TIMEOUT, version=None): try: - with open(self._key_to_file(key, version), 'r+b') as f: + with open(self._key_to_file(key, version), "r+b") as f: try: locks.lock(f, locks.LOCK_EX) if self._is_expired(f): @@ -91,7 +91,7 @@ class FileBasedCache(BaseCache): def has_key(self, key, version=None): fname = self._key_to_file(key, version) if os.path.exists(fname): - with open(fname, 'rb') as f: + with open(fname, "rb") as f: return not self._is_expired(f) return False @@ -108,8 +108,7 @@ class FileBasedCache(BaseCache): if self._cull_frequency == 0: return self.clear() # Clear the cache when CULL_FREQUENCY = 0 # Delete a random selection of entries - filelist = random.sample(filelist, - int(num_entries / self._cull_frequency)) + filelist = random.sample(filelist, int(num_entries / self._cull_frequency)) for fname in filelist: self._delete(fname) @@ -128,10 +127,15 @@ class FileBasedCache(BaseCache): root cache path joined with the md5sum of the key and a suffix. """ key = self.make_and_validate_key(key, version=version) - return os.path.join(self._dir, ''.join([ - md5(key.encode(), usedforsecurity=False).hexdigest(), - self.cache_suffix, - ])) + return os.path.join( + self._dir, + "".join( + [ + md5(key.encode(), usedforsecurity=False).hexdigest(), + self.cache_suffix, + ] + ), + ) def clear(self): """ @@ -161,5 +165,5 @@ class FileBasedCache(BaseCache): """ return [ os.path.join(self._dir, fname) - for fname in glob.glob1(self._dir, '*%s' % self.cache_suffix) + for fname in glob.glob1(self._dir, "*%s" % self.cache_suffix) ] diff --git a/django/core/cache/backends/memcached.py b/django/core/cache/backends/memcached.py index 472a28179c..2416168634 100644 --- a/django/core/cache/backends/memcached.py +++ b/django/core/cache/backends/memcached.py @@ -4,7 +4,10 @@ import re import time from django.core.cache.backends.base import ( - DEFAULT_TIMEOUT, BaseCache, InvalidCacheKey, memcache_key_warnings, + DEFAULT_TIMEOUT, + BaseCache, + InvalidCacheKey, + memcache_key_warnings, ) from django.utils.functional import cached_property @@ -13,7 +16,7 @@ class BaseMemcachedCache(BaseCache): def __init__(self, server, params, library, value_not_found_exception): super().__init__(params) if isinstance(server, str): - self._servers = re.split('[;,]', server) + self._servers = re.split("[;,]", server) else: self._servers = server @@ -23,7 +26,7 @@ class BaseMemcachedCache(BaseCache): self._lib = library self._class = library.Client - self._options = params.get('OPTIONS') or {} + self._options = params.get("OPTIONS") or {} @property def client_servers(self): @@ -86,7 +89,9 @@ class BaseMemcachedCache(BaseCache): return bool(self._cache.delete(key)) def get_many(self, keys, version=None): - key_map = {self.make_and_validate_key(key, version=version): key for key in keys} + key_map = { + self.make_and_validate_key(key, version=version): key for key in keys + } ret = self._cache.get_multi(key_map.keys()) return {key_map[k]: v for k, v in ret.items()} @@ -118,7 +123,9 @@ class BaseMemcachedCache(BaseCache): safe_key = self.make_and_validate_key(key, version=version) safe_data[safe_key] = value original_keys[safe_key] = key - failed_keys = self._cache.set_multi(safe_data, self.get_backend_timeout(timeout)) + failed_keys = self._cache.set_multi( + safe_data, self.get_backend_timeout(timeout) + ) return [original_keys[k] for k in failed_keys] def delete_many(self, keys, version=None): @@ -135,15 +142,19 @@ class BaseMemcachedCache(BaseCache): class PyLibMCCache(BaseMemcachedCache): "An implementation of a cache binding using pylibmc" + def __init__(self, server, params): import pylibmc - super().__init__(server, params, library=pylibmc, value_not_found_exception=pylibmc.NotFound) + + super().__init__( + server, params, library=pylibmc, value_not_found_exception=pylibmc.NotFound + ) @property def client_servers(self): output = [] for server in self._servers: - output.append(server[5:] if server.startswith('unix:') else server) + output.append(server[5:] if server.startswith("unix:") else server) return output def touch(self, key, timeout=DEFAULT_TIMEOUT, version=None): @@ -160,13 +171,17 @@ class PyLibMCCache(BaseMemcachedCache): class PyMemcacheCache(BaseMemcachedCache): """An implementation of a cache binding using pymemcache.""" + def __init__(self, server, params): import pymemcache.serde - super().__init__(server, params, library=pymemcache, value_not_found_exception=KeyError) + + super().__init__( + server, params, library=pymemcache, value_not_found_exception=KeyError + ) self._class = self._lib.HashClient self._options = { - 'allow_unicode_keys': True, - 'default_noreply': False, - 'serde': pymemcache.serde.pickle_serde, + "allow_unicode_keys": True, + "default_noreply": False, + "serde": pymemcache.serde.pickle_serde, **self._options, } diff --git a/django/core/cache/backends/redis.py b/django/core/cache/backends/redis.py index f168e93737..e0d30784ff 100644 --- a/django/core/cache/backends/redis.py +++ b/django/core/cache/backends/redis.py @@ -58,7 +58,7 @@ class RedisCacheClient: parser_class = import_string(parser_class) parser_class = parser_class or self._lib.connection.DefaultParser - self._pool_options = {'parser_class': parser_class, 'db': db} + self._pool_options = {"parser_class": parser_class, "db": db} def _get_connection_pool_index(self, write): # Write to the first server. Read from other servers if there are more, @@ -71,7 +71,8 @@ class RedisCacheClient: index = self._get_connection_pool_index(write) if index not in self._pools: self._pools[index] = self._pool_class.from_url( - self._servers[index], **self._pool_options, + self._servers[index], + **self._pool_options, ) return self._pools[index] @@ -159,12 +160,12 @@ class RedisCache(BaseCache): def __init__(self, server, params): super().__init__(params) if isinstance(server, str): - self._servers = re.split('[;,]', server) + self._servers = re.split("[;,]", server) else: self._servers = server self._class = RedisCacheClient - self._options = params.get('OPTIONS', {}) + self._options = params.get("OPTIONS", {}) @cached_property def _cache(self): @@ -198,7 +199,9 @@ class RedisCache(BaseCache): return self._cache.delete(key) def get_many(self, keys, version=None): - key_map = {self.make_and_validate_key(key, version=version): key for key in keys} + key_map = { + self.make_and_validate_key(key, version=version): key for key in keys + } ret = self._cache.get_many(key_map.keys()) return {key_map[k]: v for k, v in ret.items()} diff --git a/django/core/cache/utils.py b/django/core/cache/utils.py index d41960f6e4..ff2a23aa6f 100644 --- a/django/core/cache/utils.py +++ b/django/core/cache/utils.py @@ -1,6 +1,6 @@ from django.utils.crypto import md5 -TEMPLATE_FRAGMENT_KEY_TEMPLATE = 'template.cache.%s.%s' +TEMPLATE_FRAGMENT_KEY_TEMPLATE = "template.cache.%s.%s" def make_template_fragment_key(fragment_name, vary_on=None): @@ -8,5 +8,5 @@ def make_template_fragment_key(fragment_name, vary_on=None): if vary_on is not None: for arg in vary_on: hasher.update(str(arg).encode()) - hasher.update(b':') + hasher.update(b":") return TEMPLATE_FRAGMENT_KEY_TEMPLATE % (fragment_name, hasher.hexdigest()) -- cgit v1.3