Guest User

Untitled

a guest
Feb 10th, 2020
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. from functools import lru_cache
  2. import requests
  3.  
  4. @lru_cache(maxsize=32)
  5. def get_with_cache(url):
  6.     try:
  7.         r = requests.get(url)
  8.         return r.text
  9.     except:
  10.         return "Not Found"
  11.  
  12. for url in ["https://google.com/",
  13.             "https://martinheinz.dev/",
  14.             "https://reddit.com/",
  15.             "https://google.com/",
  16.             "https://dev.to/martinheinz",
  17.             "https://google.com/"]:
  18.     get_with_cache(url)
  19.  
  20. print(get_with_cache.cache_info())
  21. # CacheInfo(hits=2, misses=4, maxsize=32, currsize=4)
Add Comment
Please, Sign In to add comment