summaryrefslogtreecommitdiff
path: root/requests_cache/models
diff options
context:
space:
mode:
authorJordan Cook <jordan.cook@pioneer.com>2022-04-22 17:29:33 -0500
committerJordan Cook <jordan.cook@pioneer.com>2022-04-22 17:57:22 -0500
commit1a4468abb249ec3ea2c1a774bd14fded14e28d69 (patch)
tree8264fe9b6fd727553ec1ff2a4961b0b6564bfa81 /requests_cache/models
parent0dbd82d4d28875f2c0a592dfc89f50bf1c63cb2b (diff)
downloadrequests-cache-1a4468abb249ec3ea2c1a774bd14fded14e28d69.tar.gz
For SQLite expires column, use time.time() instead of datetime.timestamp()
Diffstat (limited to 'requests_cache/models')
-rwxr-xr-xrequests_cache/models/response.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/requests_cache/models/response.py b/requests_cache/models/response.py
index fe6e4da..9ad3a1a 100755
--- a/requests_cache/models/response.py
+++ b/requests_cache/models/response.py
@@ -2,6 +2,7 @@ from __future__ import annotations
from datetime import datetime, timedelta, timezone
from logging import getLogger
+from time import time
from typing import TYPE_CHECKING, List, Optional
import attr
@@ -134,12 +135,18 @@ class CachedResponse(BaseResponse, RichMixin):
return self.expires is not None and datetime.utcnow() >= self.expires
@property
- def ttl(self) -> Optional[float]:
+ def expires_delta(self) -> Optional[int]:
"""Get time to expiration in seconds (rounded to the nearest second)"""
if self.expires is None:
return None
delta = self.expires - datetime.utcnow()
- return delta.total_seconds()
+ return round(delta.total_seconds())
+
+ @property
+ def expires_unix(self) -> Optional[int]:
+ """Get expiration time as a Unix timestamp"""
+ seconds = self.expires_delta
+ return round(time() + seconds) if seconds else None
@property
def next(self) -> Optional[PreparedRequest]: