aiohttp-client-cache
aiohttp-client-cache copied to clipboard
Feature request: Share cache with requests-cache
Feature description
Use case
Use the same SQLite backend
Workarounds
Have the same key generation
Plan to implement
Maybe
from aiohttp_client_cache import CachedSession, SQLiteBackend
import requests_cache
cache = "drive/MyDrive/xyz.sqlite"
url = 'https://example.com'
requests_cache.install_cache(cache)
requests.get(url)
async def main():
global url
async with CachedSession(cache=SQLiteBackend(cache)) as session:
r = await session.get(url)
print(r.from_cache)
await main()
This evaluates to False, but should be True
I agree that this would be nice to have. Unfortunately this would require quite a bit more work than just changing the cache keys. Problems include:
- requests-cache uses a different serialization format using the cattrs library
aiohttp.ClientResponseresponse objects look quite different fromrequests.Responseobjects- Objects serialized with
pickleare tied to a specific class, and will throw an error if the original serialized class isn't available
A possible solution might look something like:
- Update this library to use cattrs (to "unstructure" a response object into primitive types before pickling)
- Make a new response class compatible with both aiohttp and requests
- And/or: Update both requests-cache and aiohttp-client cache to handle missing attributes unique to each HTTP library
- Add all (or most) of requests-cache's request matching behavior to this library so cache keys will be the same
There could be a simpler solution, but I can't think of one right now.