Parameter time_to_live do it for hours, days, etc..
zuenko opened this issue · 2 comments
zuenko commented
async-cache/cache/async_ttl.py
Line 34 in 20a9fda
async-cache/cache/async_ttl.py
Line 11 in 20a9fda
It is better to pass the exact parameter for
@AsyncTTL(hours=1, seconds=1, days=0, milliseconds=0, ... etc. , maxsize=1024)
datetime.timedelta(
days=days,
seconds=seconds,
microseconds=microseconds,
milliseconds=milliseconds,
minutes=minutes,
hours=hours,
weeks=weeks
)
iamsinghrajat commented
@zuenko @inktrap We can easily pass time_to_live
argument in seconds, datetime library will automatically convert it into microseconds or days accordingly. Passing hours
,minutes
, seconds
or datetime object as argument separately make things complex.
>> datetime.timedelta(seconds=0.05)
datetime.timedelta(microseconds=50000)
>> datetime.timedelta(seconds=5000000)
datetime.timedelta(days=57, seconds=75200)
inktrap commented
Yes, of course, this forces you to use datetime objects. Also this follows other formats, like cachetools https://cachetools.readthedocs.io/en/stable/#
If you don't want to do that and keep it in seconds, I would change the docs to use timedelta beforehand, because it is much clearer and easier to write day=1 instead of writing something like 60*60*24. That's what timedelta is for.
But then I'll see no point in keeping this open and implementing hours, days, minutes, as params because it just duplicates timedelta.
…On 09/03/22 12:40AM, Rajat Singh wrote:
@zuenko @inktrap We can easily pass `time_to_live` argument in seconds, datetime library will automatically convert it into microseconds or days accordingly. Passing `hours`,`minutes`, `seconds` or datetime object as argument separately make things complex.
```
>> datetime.timedelta(seconds=0.05)
datetime.timedelta(microseconds=50000)
```
```
>> datetime.timedelta(seconds=5000000)
datetime.timedelta(days=57, seconds=75200)
```
--
Reply to this email directly or view it on GitHub:
#11 (comment)
You are receiving this because you were mentioned.
Message ID: ***@***.***>