Skip to content

Commit

Permalink
Merge pull request django-cms#7910 from wfehr/develop
Browse files Browse the repository at this point in the history
fix: also use key-length of 200 for the actual cache-key of placeholders
  • Loading branch information
fsbraun authored May 6, 2024
2 parents 5fe8855 + 108986b commit c3022a8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cms/cache/placeholder.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,13 @@ def _get_placeholder_cache_key(placeholder, lang, site_id, request, soft=False):
if sub_key_list:
cache_key += '|' + '|'.join(sub_key_list)

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

0 comments on commit c3022a8

Please sign in to comment.