Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions newspaper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,17 @@ def inner_function(*args, **kwargs):
modified = os.path.getmtime(filepath)
age_seconds = time.time() - modified
if age_seconds < seconds:
return pickle.load(open(filepath, "rb"))
cache_file = open(filepath, "rb")
content = pickle.load(cache_file)
cache_file.close()
return content

# call the decorated function...
result = function(*args, **kwargs)
# ... and save the cached object for next time
pickle.dump(result, open(filepath, "wb"))
cache_file = open(filepath, "wb")
pickle.dump(result, cache_file)
cache_file.close()
return result
return inner_function
return do_cache
Expand Down