-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add cache_disabled extension * Add test and implementation for httpcore * Add extensions section * revise changelog and document extensions * Update CHANGELOG.md Co-authored-by: Kar Petrosyan <[email protected]> * update and simplify extension docs --------- Co-authored-by: karpetrosyan <[email protected]> Co-authored-by: Kar Petrosyan <[email protected]>
- Loading branch information
1 parent
03d8189
commit a6b4c65
Showing
12 changed files
with
290 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
--- | ||
icon: material/apps | ||
--- | ||
|
||
# Extensions | ||
|
||
`HTTPX` provides an extension mechanism to allow additional information | ||
to be added to requests and to be returned in responses. `hishel` makes use | ||
of these extensions to expose some additional cache-related options and metadata. | ||
These extensions are available from either the `hishel.CacheClient` / | ||
`hishel.AsyncCacheClient` or a `httpx.Client` / `httpx.AsyncCacheClient` | ||
using a `hishel` transport. | ||
|
||
## Request extensions | ||
|
||
### cache_disabled | ||
|
||
This extension temporarily disables the cache by passing appropriate RFC9111 headers to | ||
ignore cached responses and to not store incoming responses. For example: | ||
|
||
```python | ||
>>> import hishel | ||
>>> client = hishel.CacheClient() | ||
>>> response = client.get("https://www.example.com/cacheable-endpoint", extensions={"cache_disabled": True}) | ||
|
||
``` | ||
This feature is more fully documented in the [User Guide](/userguide/#temporarily-disabling-the-cache) | ||
|
||
## Response extensions | ||
|
||
### from_cache | ||
|
||
Every response from will have a `from_cache` extension value that will be `True` when the response was retrieved | ||
from the cache, and `False` when the response was received over the network. | ||
|
||
```python | ||
>>> import hishel | ||
>>> client = hishel.CacheClient() | ||
>>> response = client.get("https://www.example.com") | ||
>>> response.extensions["from_cache"] | ||
False | ||
>>> response = client.get("https://www.example.com") | ||
>>> response.extensions["from_cache"] | ||
True | ||
``` | ||
|
||
### cache_metadata | ||
|
||
If `from_cache` is `True`, the response will also include a `cache_metadata` extension with additional information about | ||
the response retrieved from the cache. If `from_cache` is `False`, then `cache_metadata` will not | ||
be present in the response extensions. | ||
|
||
Example: | ||
|
||
```python | ||
>>> import hishel | ||
>>> client = hishel.CacheClient() | ||
>>> response = client.get("https://www.example.com/cacheable-endpoint") | ||
>>> response.extensions | ||
{ | ||
... # other extensions | ||
"from_cache": False | ||
} | ||
>>> response = client.get("https://www.example.com/cacheable-endpoint") | ||
>>> response.extensions | ||
{ | ||
... # other extensions | ||
"from_cache": True | ||
"cache_metadata" : { | ||
"cache_key': '1a4c648c9a61adf939eef934a73e0cbe', | ||
'created_at': datetime.datetime(2020, 1, 1, 0, 0, 0), | ||
'number_of_uses': 1, | ||
} | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters