8000 Bugfix: avoid InvalidCacheKey (memcached) for key-length ~249 (fixes … · fsbraun/django-cms@d9ce1e5 · GitHub
[go: up one dir, main page]

Skip to content

Commit d9ce1e5

Browse files
wfehrfsbraun
authored andcommitted
Bugfix: avoid InvalidCacheKey (memcached) for key-length ~249 (fixes django-cms#7595) (django-cms#7657)
1 parent 4f8aee4 commit d9ce1e5

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

cms/cache/placeholder.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ def _get_placeholder_cache_version_key(placeholder, lang, site_id):
4141
lang=str(lang),
4242
site=site_id,
4343
)
44-
if len(key) > 250:
44+
# django itself adds "version" add the end of cache-keys, e.g. "<key>:1".
45+
# -> If `cache.set()` is for example called with `version=""`, it still adds
46+
# `:` at the end. So if we check the length for `> 250`, a length of 249
47+
# or even 250 ends up in an InvalidCacheKey-exception.
48+
# In order to avoid these errors, we hash the keys at a lower length to also
49+
# have a little buffer.
50+
if len(key) > 200:
4551
key = '{prefix}|{hash}'.format(
4652
prefix=prefix,
4753
hash=hashlib.sha1(key.encode('utf-8')).hexdigest(),

0 commit comments

Comments
 (0)
0