Skip to content

Instantly share code, notes, and snippets.

@jugmac00
Last active October 10, 2020 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jugmac00/8f722ce20b315ac66b0e69254827b6ee to your computer and use it in GitHub Desktop.
Save jugmac00/8f722ce20b315ac66b0e69254827b6ee to your computer and use it in GitHub Desktop.
simple cache
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