Skip to content

Commit

Permalink
Merge pull request #7911 from fsbraun/fix/placeholder-cache
Browse files Browse the repository at this point in the history
chore: Port forward of #7910
  • Loading branch information
fsbraun committed May 6, 2024
2 parents ac454ce + 9c42159 commit 494c346
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cms/cache/placeholder.py
Expand Up @@ -119,7 +119,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 494c346

Please sign in to comment.