karpetrosyan / hishel

An elegant HTTP Cache implementation for HTTPX and HTTP Core.
https://hishel.com
BSD 3-Clause "New" or "Revised" License
158 stars 19 forks source link

Add `revalidated` extension #242

Closed karpetrosyan closed 2 months ago

karpetrosyan commented 2 months ago

Every response will have a revalidated extension that indicates whether the response has been revalidated or not.

Note that a response could have revalidated set to True even when from_cache is set to False. This occurs when the cached entry has been updated and a new entry is downloaded during revalidation.

>>> import hishel
>>> client = hishel.CacheClient()
>>> response = client.get("https://www.example.com/endpoint_that_is_fresh")
>>> response.extensions["revalidated"]
False
>>> response = client.get("https://www.example.com/endpoint_that_is_stale")
>>> response.extensions["revalidated"]
True