From 630d7d239ba6a61542740a02a338ba438456e144 Mon Sep 17 00:00:00 2001 From: Bertrand Bordage Date: Sat, 11 Apr 2015 02:38:52 +0200 Subject: [PATCH] Always hash table cache keys because of an inconsistency between python-memcached 1.53 & 1.54. --- cachalot/utils.py | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/cachalot/utils.py b/cachalot/utils.py index 151b3b8..ebaefb4 100644 --- a/cachalot/utils.py +++ b/cachalot/utils.py @@ -12,19 +12,10 @@ if DJANGO_GTE_1_7: from django.utils.module_loading import import_string else: from django.utils.module_loading import import_by_path as import_string -from django.utils.six import PY3 from .settings import cachalot_settings -# The only cache backend with a key length limit is memcached (limited to -# 255 characters). However, we hash keys on other backends as well to avoid -# unnecessary huge communication between processes. -# We set the limit to something smaller than 255 because a prefix might be -# added by Django. -MAX_CACHE_KEY_LENGTH = 200 - - def get_query_cache_key(compiler): """ Generates a cache key from a SQLCompiler. @@ -40,8 +31,6 @@ def get_query_cache_key(compiler): """ sql, params = compiler.as_sql() cache_key = '%s:%s:%s' % (compiler.using, sql, params) - # We always hash queries since they are nearly always longer than - # ``MAX_CACHE_KEY_LENGTH``. return sha1(cache_key.encode('utf-8')).hexdigest() @@ -57,15 +46,7 @@ def get_table_cache_key(db_alias, table): :rtype: str """ cache_key = '%s:%s' % (db_alias, table) - # We check if we have to hash the key since it should nearly never be - # necessary. - if len(cache_key) > MAX_CACHE_KEY_LENGTH: - return sha1(cache_key.encode('utf-8')).hexdigest() - # Because of a bug in python-memcached3, we have to encode - # cache keys to bytes or it fails with this backend. - if PY3: - return cache_key.encode() - return cache_key + return sha1(cache_key.encode('utf-8')).hexdigest() def _get_query_cache_key(compiler):