From 348f512058799621a848094ec1a05b358bc2a3c9 Mon Sep 17 00:00:00 2001 From: neingeist Date: Fri, 29 Aug 2014 22:21:14 +0200 Subject: [PATCH] support multiple functions sharing the same json memo file --- json_memoize.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/json_memoize.py b/json_memoize.py index 491eaed..4b62f9c 100644 --- a/json_memoize.py +++ b/json_memoize.py @@ -28,7 +28,7 @@ def json_memoize(filename): with open(filename, "r") as f: memo = json.load(f) - json_key = repr((args, HashableDict(kwargs))) + json_key = repr((self.fn.__name__, args, HashableDict(kwargs))) if json_key not in memo: memo[json_key] = self.fn(*args, **kwargs) with open(filename, "w") as f: @@ -72,12 +72,12 @@ def is_prime(n): return True -@json_memoize('json_memoize_tmp2.json') +@json_memoize('json_memoize_tmp.json') def multiply(*args): return reduce(operator.mul, args, 1) -@json_memoize('json_memoize_tmp3.json') +@json_memoize('json_memoize_tmp.json') def some_with_kwargs(one, two, **kwargs): return one + two + reduce(operator.add, [kwargs[k] for k in kwargs], 0)