mirror of https://github.com/django/django.git
Fixed #34681 -- Optimized memcache_key_warnings().
This commit is contained in:
parent
6fbe5287ac
commit
1dbcf9a005
|
@ -6,6 +6,7 @@ from asgiref.sync import sync_to_async
|
|||
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.utils.module_loading import import_string
|
||||
from django.utils.regex_helper import _lazy_re_compile
|
||||
|
||||
|
||||
class InvalidCacheBackendError(ImproperlyConfigured):
|
||||
|
@ -388,16 +389,17 @@ class BaseCache:
|
|||
pass
|
||||
|
||||
|
||||
memcached_error_chars_re = _lazy_re_compile(r"[\x00-\x20\x7f]")
|
||||
|
||||
|
||||
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)
|
||||
)
|
||||
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
|
||||
)
|
||||
break
|
||||
if memcached_error_chars_re.search(key):
|
||||
yield (
|
||||
"Cache key contains characters that will cause errors if used with "
|
||||
f"memcached: {key!r}"
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue