MCPcopy
hub / github.com/codelucas/newspaper / inner_function

Function inner_function

newspaper/utils.py:194–214  ·  view source on GitHub ↗

Calculate a cache key based on the decorated method signature args[1] indicates the domain of the inputs, we hash on domain!

(*args, **kwargs)

Source from the content-addressed store, hash-verified

192 """
193 def do_cache(function):
194 def inner_function(*args, **kwargs):
195 """Calculate a cache key based on the decorated method signature
196 args[1] indicates the domain of the inputs, we hash on domain!
197 """
198 key = sha1((str(args[1]) +
199 str(kwargs)).encode('utf-8')).hexdigest()
200 filepath = os.path.join(cache_folder, key)
201
202 # verify that the cached object exists and is less than
203 # X seconds old
204 if os.path.exists(filepath):
205 modified = os.path.getmtime(filepath)
206 age_seconds = time.time() - modified
207 if age_seconds < seconds:
208 return pickle.load(open(filepath, "rb"))
209
210 # call the decorated function...
211 result = function(*args, **kwargs)
212 # ... and save the cached object for next time
213 pickle.dump(result, open(filepath, "wb"))
214 return result
215 return inner_function
216 return do_cache
217

Callers

nothing calls this directly

Calls 1

joinMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…