8000 Fix: also use key-length of 200 for the actual cache-key of placeholders · fsbraun/django-cms@4727131 · GitHub 8000
[go: up one dir, main page]

Skip to content

Commit 4727131

Browse files
wfehrfsbraun
authored andcommitted
Fix: also use key-length of 200 for the actual cache-key of placeholders
- missing "functionality" for changes of django-cms#7595 and django-cms#7657
1 parent 8486a64 commit 4727131

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
@@ -133,7 +133,13 @@ def _get_placeholder_cache_key(placeholder, lang, site_id, request, soft=False):
133133
if sub_key_list:
134134
cache_key += '|' + '|'.join(sub_key_list)
135135

136-
if len(cache_key) > 250:
136+
# django itself adds "version" add the end of cache-keys, e.g. "<key>:1".
137+
# -> If `cache.set()` is for example called with `version=""`, it still adds
138+
# `:` at the end. So if we check the length for `> 250`, a length of 249
139+
# or even 250 ends up in an InvalidCacheKey-exception.
140+
# In order to avoid these errors, we hash the keys at a lower length to also
141+
# have a little buffer.
142+
if len(cache_key) > 200:
137143
cache_key = '{prefix}|{hash}'.format(
138144
prefix=prefix,
139145
hash=hashlib.sha1(cache_key.encode('utf-8')).hexdigest(),

0 commit comments

Comments
 (0)
0