Persistent cache for aiohttp requests
Project description
aiohttp-client-cache
See full documentation at https://aiohttp-client-cache.readthedocs.io
aiohttp-client-cache
is an async persistent cache for aiohttp
requests, based on requests-cache.
Not to be confused with aiohttp-cache, which is a cache for the aiohttp web server. This package is, as you might guess, specifically for the aiohttp client.
This is an early work in progress and not yet fully functional!
Installation
Requires python 3.7+
Install the latest stable version with pip:
pip install aiohttp-client-cache
To set up for local development:
$ git clone https://github.com/JWCook/aiohttp-client-cache
$ cd aiohttp-client-cache
$ pip install -Ue ".[dev]"
Usage example
from aiohttp_client_cache import CachedSession
session = CachedSession('demo_cache', backend='sqlite')
response = await session.get('http://httpbin.org/get')
Afterward, all responses with headers and cookies will be transparently cached to
a database named demo_cache.sqlite
. For example, following code will take only
1-2 seconds instead of 10, and will run instantly on next launch:
for i in range(10):
await session.get('http://httpbin.org/delay/1')
Cache Backends
Several backends are available:
sqlite
: SQLite database (default)redis
: Stores all data in a redis cache (requires redis-py)mongodb
: MongoDB database (requires pymongo))gridfs
: MongoDB GridFS enables storage of documents greater than 16MB
memory
: Not persistent, simply stores all data in Pythondict
in memory
You can also provide your own backend by subclassing aiohttp_client_cache.backends.BaseCache
.
Expiration
If you are using the expire_after
parameter , responses are removed from the storage the next time
the same request is made. If you want to manually purge all expired items, you can use
CachedSession.delete_expired_responses
. Example:
session = CachedSession(expire_after=1)
await session.remove_expired_responses()
History
0.1.0
- Initial PyPI release
- First pass at a general refactor and conversion from
requests
toaiohttp
requests-cache
See requests-cache development history and contributors for details on prior changes.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file aiohttp-client-cache-0.1.0.tar.gz
.
File metadata
- Download URL: aiohttp-client-cache-0.1.0.tar.gz
- Upload date:
- Size: 23.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | adbf53bb33d411b4a07e0684ae252b355cd2b1f8a07e3ab93bb4f9f09333e9ec |
|
MD5 | 55d5693ebdced03453731a426bb84d02 |
|
BLAKE2b-256 | cdfc8c342437623f17282a04dbf1adeb7b0310dcf3e2b3b893d32e32300facbf |
File details
Details for the file aiohttp_client_cache-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: aiohttp_client_cache-0.1.0-py3-none-any.whl
- Upload date:
- Size: 26.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4361a0c25abf9fc19c8dd7639850304f57eb8a505712cd344353e29c711a967 |
|
MD5 | 4cd53d2fdd16d5cf6a83e7603afda8c8 |
|
BLAKE2b-256 | ac1c7165a4bf99697755630a9558fbd4cff47dd30dfd8b7768842c1f080cf28f |