Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Share cache with requests-cache #157

Open
franz101 opened this issue Jul 11, 2023 · 1 comment
Open

Feature request: Share cache with requests-cache #157

franz101 opened this issue Jul 11, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@franz101
Copy link

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

@franz101 franz101 added the enhancement New feature or request label Jul 11, 2023
@JWCook
Copy link
Member

JWCook commented Jul 11, 2023

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:

  1. requests-cache uses a different serialization format using the cattrs library
  2. aiohttp.ClientResponse response objects look quite different from requests.Response objects
  3. Objects serialized with pickle are 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants