-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ef0012
commit 5af811f
Showing
5 changed files
with
31 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,30 @@ | ||
import os | ||
|
||
__cache = {} | ||
|
||
|
||
def cache_result(func): | ||
def cache_result(cwd=False): | ||
""" | ||
Function to cache the result of a function. | ||
""" | ||
def wrapper(*args, **kwargs): | ||
if func.__name__ in __cache: | ||
return __cache[func.__name__] | ||
result = func(*args, **kwargs) | ||
__cache[func.__name__] = result | ||
return result | ||
return wrapper | ||
def decorator(func): | ||
def wrapper(*args, **kwargs): | ||
if cwd: | ||
key = (func.__name__, os.getcwd()) | ||
else: | ||
key = func.__name__ | ||
|
||
if key in __cache: | ||
return __cache[key] | ||
result = func(*args, **kwargs) | ||
__cache[key] = result | ||
return result | ||
return wrapper | ||
return decorator | ||
|
||
|
||
def clear_cache(): | ||
""" | ||
Function to clear the cache. | ||
""" | ||
__cache.clear() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters