Last active
October 10, 2020 10:31
-
-
Save jugmac00/8f722ce20b315ac66b0e69254827b6ee to your computer and use it in GitHub Desktop.
simple cache
This file contains hidden or 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
from time import sleep | |
cache = dict() | |
def get_data(): | |
if not cache.get("items"): | |
sleep(10) # simulates waiting for data | |
items = ["a", "b", "c"] | |
cache["items"] = items | |
return cache["items"] | |
def main(): | |
print(get_data()) # takes 10 seconds | |
print(get_data()) # takes almost no time | |
print(get_data()) # takes almost no time | |
if __name__ == '__main__': | |
exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment