TTL Cache

from cachetools import TTLCache
cache = TTLCache(maxsize=10, ttl=10)
cache['city'] = 'Toronto'
cache['city']
'Toronto'
# Run the cell below after 10 seconds
cache['city']
'Toronto'
# more 
# https://stackoverflow.com/questions/31771286/python-in-memory-cache-with-time-to-live