Skip to content

Commit c3022a8

Browse files
authored
Merge pull request #7910 from wfehr/develop
fix: also use key-length of 200 for the actual cache-key of placeholders
2 parents 5fe8855 + 108986b commit c3022a8

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)