mirror of
https://github.com/django/django.git
synced 2025-03-06 07:22:32 +00:00
Fixed #34681 -- Optimized memcache_key_warnings().
This commit is contained in:
parent
6fbe5287ac
commit
1dbcf9a005
12
django/core/cache/backends/base.py
vendored
12
django/core/cache/backends/base.py
vendored
@ -6,6 +6,7 @@ from asgiref.sync import sync_to_async
|
|||||||
|
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
from django.utils.module_loading import import_string
|
from django.utils.module_loading import import_string
|
||||||
|
from django.utils.regex_helper import _lazy_re_compile
|
||||||
|
|
||||||
|
|
||||||
class InvalidCacheBackendError(ImproperlyConfigured):
|
class InvalidCacheBackendError(ImproperlyConfigured):
|
||||||
@ -388,16 +389,17 @@ class BaseCache:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
memcached_error_chars_re = _lazy_re_compile(r"[\x00-\x20\x7f]")
|
||||||
|
|
||||||
|
|
||||||
def memcache_key_warnings(key):
|
def memcache_key_warnings(key):
|
||||||
if len(key) > MEMCACHE_MAX_KEY_LENGTH:
|
if len(key) > MEMCACHE_MAX_KEY_LENGTH:
|
||||||
yield (
|
yield (
|
||||||
"Cache key will cause errors if used with memcached: %r "
|
"Cache key will cause errors if used with memcached: %r "
|
||||||
"(longer than %s)" % (key, MEMCACHE_MAX_KEY_LENGTH)
|
"(longer than %s)" % (key, MEMCACHE_MAX_KEY_LENGTH)
|
||||||
)
|
)
|
||||||
for char in key:
|
if memcached_error_chars_re.search(key):
|
||||||
if ord(char) < 33 or ord(char) == 127:
|
|
||||||
yield (
|
yield (
|
||||||
"Cache key contains characters that will cause errors if "
|
"Cache key contains characters that will cause errors if used with "
|
||||||
"used with memcached: %r" % key
|
f"memcached: {key!r}"
|
||||||
)
|
)
|
||||||
break
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user