Commit 86af6e35 authored by Jérome Perrin's avatar Jérome Perrin

Cache: compute cache id in a deterministic way

by using str on a dict we don't produce consistent results depending
on hash randomization. This was visible with erp5_core_test:testCacheTool
and PYTHONHASHSEED 12 , the cache id generated in
https://lab.nexedi.com/nexedi/erp5/-/blob/a0aa9184d/bt5/erp5_core_test/TestTemplateItem/portal_components/test.erp5.testCacheTool.py#L216-218
was
"('py_script_obj', (60000,), {'result': 'a short value', 'portal_path': ('', 'erp5')})"

and the cache id generated in
https://lab.nexedi.com/nexedi/erp5/-/blob/a0aa9184d/bt5/erp5_core_test/TestTemplateItem/portal_components/test.erp5.testCacheTool.py#L239-241
with same arguments for delete was
 "('py_script_obj', (60000,), {'portal_path': ('', 'erp5'), 'result': 'a short value'})")
parent 6e7fdd72
Pipeline #33423 passed with stage
in 0 seconds
...@@ -225,11 +225,11 @@ class CachingMethod: ...@@ -225,11 +225,11 @@ class CachingMethod:
## generate cache id out of arguments passed. ## generate cache id out of arguments passed.
## depending on arguments we may have different ## depending on arguments we may have different
## cache_id for same method_id ## cache_id for same method_id
return str((method_id, args, kw)) return str((method_id, args, sorted(kw.items())))
@staticmethod @staticmethod
def erasable_cache_id_generator(method_id, obj, *args, **kw): def erasable_cache_id_generator(method_id, obj, *args, **kw):
return str((method_id, obj.getCacheCookie(method_id), args, kw)) return str((method_id, obj.getCacheCookie(method_id), args, sorted(kw.items())))
def __init__(self, callable_object, id, cache_duration=180, def __init__(self, callable_object, id, cache_duration=180,
cache_factory=DEFAULT_CACHE_FACTORY, cache_factory=DEFAULT_CACHE_FACTORY,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment