You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I realized that cachetools is not typed, but I was wondering whether the ttl argument for the TTLCache class should also support a datetime.timedelta object for specifying (and preferably storing) the TTL, i.e.,
The reason I ask is using an int for encoding the TTL is somewhat difficult to grok as i) it is not apparent what the units are, and ii) larger TTL become hard to comprehend resulting in people including a comment for readability like,
The ttl argument has to be compatible with the result of the timer function, at least so that it can be added to and the result compared with timer(), so you could try for example (not tested)
import cachetools
import datetime
c = cachetools.TTLCache(maxsize=10, ttl=datetime.timedelta(seconds=10), timer=datetime.datetime.now)
Typings support for cachetools is provided by typeshed, but expressing these kinds of dependencies isn't so easy, apparently, so ttl is just float there. Maybe you can contribute to improve the situation over there?
I realized that
cachetools
is not typed, but I was wondering whether thettl
argument for theTTLCache
class should also support adatetime.timedelta
object for specifying (and preferably storing) the TTL, i.e.,The reason I ask is using an
int
for encoding the TTL is somewhat difficult to grok as i) it is not apparent what the units are, and ii) larger TTL become hard to comprehend resulting in people including a comment for readability like,@cached(cache=TTLCache(maxsize=1024, ttl=86400)) # 24 hours
or
@cached(cache=TTLCache(maxsize=1024, ttl=60 * 60 * 24)) # 24 hours
rather than simply writing
@cached(cache=TTLCache(maxsize=1024, ttl=timedelta(hours=24)))
The text was updated successfully, but these errors were encountered: