Ttl-Cache-1
Sat 17 May 2025
title: "TTL Cache Check" author: "Rj" date: 2019-04-20 description: "-" type: technical_note draft: false
from cachetools import TTLCache
import time
cache = TTLCache(maxsize=10, ttl=10)
cache['city'] = 'Toronto'
print(cache['city'])
Toronto
time.sleep(5)
if('city' in cache):
print(cache['city'])
else:
print('Cache not found')
Toronto
time.sleep(5)
print('city' in cache)
False
Score: 5
Category: basics