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

Skip to content

Commit 3576391

Browse files
authored
Bugfix: avoid InvalidCacheKey (memcached) for key-length ~249 (fixes #7595) (#7657)
1 parent f5292d1 commit 3576391

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
@@ -43,7 +43,13 @@ def _get_placeholder_cache_version_key(placeholder, lang, site_id):
4343
lang=str(lang),
4444
site=site_id,
4545
)
46-
if len(key) > 250:
46+
# django itself adds "version" add the end of cache-keys, e.g. "<key>:1".
47+
# -> If `cache.set()` is for example called with `version=""`, it still adds
48+
# `:` at the end. So if we check the length for `> 250`, a length of 249
49+
# or even 250 ends up in an InvalidCacheKey-exception.
50+
# In order to avoid these errors, we hash the keys at a lower length to also
51+
# have a little buffer.
52+
if len(key) > 200:
4753
key = '{prefix}|{hash}'.format(
4854
prefix=prefix,
4955
hash=hashlib.sha1(key.encode('utf-8')).hexdigest(),

0 commit comments

Comments
 (0)
0