Skip to content

Commit

Permalink
adjust copy logic for cached dict
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Whitehead <[email protected]>
  • Loading branch information
andrewwhitehead committed Jan 28, 2025
1 parent de7725f commit 3b6f53c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions wrappers/python/aries_askar/bindings/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import sys
import threading
import time
from copy import deepcopy

try:
import orjson as json
Expand Down Expand Up @@ -59,12 +60,13 @@ def wrapper(self, index: int):
cache = self._ecache
ckey = (fn, index)
if ckey in cache:
return cache[ckey]
res = fn(self, index)
cache[ckey] = res
res = cache[ckey]
else:
res = fn(self, index)
cache[ckey] = res
if isinstance(res, dict):
# make sure the cached copy is not mutated
res = dict(res)
res = deepcopy(res)
return res

return wrapper
Expand Down

0 comments on commit 3b6f53c

Please sign in to comment.