Fix: also use key-length of 200 for the actual cache-key of placeholders

- missing "functionality" for changes of #7595 and #7657
This commit is contained in:
Wolfgang Fehr 2024-05-06 06:47:32 +02:00
parent 5fe8855a46
commit 108986ba5a

View File

@ -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(),