summaryrefslogtreecommitdiff
path: root/django/core/cache/backends/base.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/core/cache/backends/base.py')
-rw-r--r--django/core/cache/backends/base.py33
1 files changed, 21 insertions, 12 deletions
diff --git a/django/core/cache/backends/base.py b/django/core/cache/backends/base.py
index b3a65ab40f..86a7aca575 100644
--- a/django/core/cache/backends/base.py
+++ b/django/core/cache/backends/base.py
@@ -14,6 +14,10 @@ class CacheKeyWarning(RuntimeWarning):
pass
+class InvalidCacheKey(ValueError):
+ pass
+
+
# Stub class to ensure not passing in a `timeout` argument results in
# the default timeout
DEFAULT_TIMEOUT = object()
@@ -241,18 +245,8 @@ class BaseCache:
backend. This encourages (but does not force) writing backend-portable
cache code.
"""
- if len(key) > MEMCACHE_MAX_KEY_LENGTH:
- warnings.warn(
- 'Cache key will cause errors if used with memcached: %r '
- '(longer than %s)' % (key, MEMCACHE_MAX_KEY_LENGTH), CacheKeyWarning
- )
- for char in key:
- if ord(char) < 33 or ord(char) == 127:
- warnings.warn(
- 'Cache key contains characters that will cause errors if '
- 'used with memcached: %r' % key, CacheKeyWarning
- )
- break
+ for warning in memcache_key_warnings(key):
+ warnings.warn(warning, CacheKeyWarning)
def incr_version(self, key, delta=1, version=None):
"""
@@ -280,3 +274,18 @@ class BaseCache:
def close(self, **kwargs):
"""Close the cache connection"""
pass
+
+
+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, CacheKeyWarning
+ )
+ break