[docs]classCachedItem:'''a Cached Item Args: value (Any): the stored Value ttl (int): the time_to_live for the item'''def__init__(self,value:Any,ttl:int=-1):self.value=valueself.ttl=time.time()+(ttlifnotttl==-1elsefloat("inf"))@propertydefhas_expired(self)->bool:'''check if the item has passed its ttl or not'''returntime.time()>=self.ttl
[docs]defget(self)->Optional[Any]:'''used to return the item value if it has not expired yet.'''returnself.valueifnotself.has_expiredelseNone