diff options
| author | Jordan Cook <jordan.cook@pioneer.com> | 2021-08-21 18:39:52 -0500 |
|---|---|---|
| committer | Jordan Cook <jordan.cook@pioneer.com> | 2021-12-01 12:45:43 -0600 |
| commit | 7e0690254ed45fa66f8b38571a9efd8fddda73cf (patch) | |
| tree | 7aab1adaa68fce189f81974130bfa35a1d91b450 /requests_cache/models | |
| parent | 85dce906c7b8d7343098c0b76571a3293c860d8d (diff) | |
| download | requests-cache-7e0690254ed45fa66f8b38571a9efd8fddda73cf.tar.gz | |
Add a new RedisDict class that stores responses in separate hashes instead of in a single hash
Diffstat (limited to 'requests_cache/models')
| -rwxr-xr-x | requests_cache/models/response.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/requests_cache/models/response.py b/requests_cache/models/response.py index ec65034..561d6c8 100755 --- a/requests_cache/models/response.py +++ b/requests_cache/models/response.py @@ -96,6 +96,14 @@ class CachedResponse(Response): return self.expires is not None and datetime.utcnow() >= self.expires @property + def ttl(self) -> Optional[int]: + """Get time to expiration in seconds""" + if self.expires is None or self.is_expired: + return None + delta = self.expires - datetime.utcnow() + return int(delta.total_seconds()) + + @property def next(self) -> Optional[PreparedRequest]: """Returns a PreparedRequest for the next request in a redirect chain, if there is one.""" return self._next.prepare() if self._next else None |
