File tree 3 files changed +10
-4
lines changed
3 files changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -153,6 +153,10 @@ We have another problem - we want to miss our cache under two conditions:
153
153
To handle 2. we used ` inspect.getsource(func) ` to add the function's source code to the hash, correctly missing the cache when the the code changes.
154
154
155
155
``` python /hash_code(inspect.getsource(func))/
156
+ func_source_code_hash = hash_code(inspect.getsource(func))
157
+ ```
158
+
159
+ ``` python /func_source_code_hash/
156
160
args_names = func.__code__ .co_varnames[: func.__code__ .co_argcount]
157
161
args_dict = dict (zip (args_names, args))
158
162
@@ -166,7 +170,7 @@ To handle 2. we used `inspect.getsource(func)` to add the function's source code
166
170
arg_hash = (
167
171
recursive_hash(args_dict, ignore_params = ignore_params)
168
172
+ recursive_hash(kwargs_clone, ignore_params = ignore_params)
169
- + hash_code(inspect.getsource(func))
173
+ + func_source_code_hash
170
174
)
171
175
cache_file = os.path.join(
172
176
cache_dir, f " { func.__module__ } _ { func.__name__ } _ { arg_hash} .pickle "
Original file line number Diff line number Diff line change @@ -57,6 +57,7 @@ def decorator(func):
57
57
if verbose :
58
58
print ("Cache is disabled for function: " + func .__name__ )
59
59
return func
60
+ func_source_code_hash = hash_code (inspect .getsource (func ))
60
61
61
62
def wrapper (* args , ** kwargs ):
62
63
cache_dir = "/tmp/file_cache"
@@ -76,7 +77,7 @@ def wrapper(*args, **kwargs):
76
77
arg_hash = (
77
78
recursive_hash (args_dict , ignore_params = ignore_params )
78
79
+ recursive_hash (kwargs_clone , ignore_params = ignore_params )
79
- + hash_code ( inspect . getsource ( func ))
80
+ + func_source_code_hash
80
81
)
81
82
cache_file = os .path .join (
82
83
cache_dir , f"{ func .__module__ } _{ func .__name__ } _{ arg_hash } .pickle"
@@ -103,4 +104,4 @@ def wrapper(*args, **kwargs):
103
104
104
105
return wrapper
105
106
106
- return decorator
107
+ return decorator
Original file line number Diff line number Diff line change @@ -56,6 +56,7 @@ def file_cache(ignore_params=[], verbose=False):
56
56
def decorator (func ):
57
57
if DEBUG :
58
58
return func
59
+ func_source_code_hash = hash_code (inspect .getsource (func ))
59
60
60
61
def wrapper (* args , ** kwargs ):
61
62
cache_dir = "/tmp/file_cache"
@@ -75,7 +76,7 @@ def wrapper(*args, **kwargs):
75
76
arg_hash = (
76
77
recursive_hash (args_dict , ignore_params = ignore_params )
77
78
+ recursive_hash (kwargs_clone , ignore_params = ignore_params )
78
- + hash_code ( inspect . getsource ( func ))
79
+ + func_source_code_hash
79
80
)
80
81
cache_file = os .path .join (
81
82
cache_dir , f"{ func .__module__ } _{ func .__name__ } _{ arg_hash } .pickle"
You can’t perform that action at this time.
0 commit comments