{"id":6491,"library":"acachecontrol","title":"acachecontrol","description":"acachecontrol is an asynchronous library that provides Cache-Control functionality for aiohttp. It aims to bridge the gap left by `requests-cache` for the popular `aiohttp` client, allowing developers to easily implement HTTP caching. The library is currently at version 0.3.7 and receives updates to address issues and maintain compatibility with its dependencies.","status":"active","version":"0.3.7","language":"en","source_language":"en","source_url":"https://github.com/MasterSergius/acachecontrol","tags":["aiohttp","caching","http","async","cache-control"],"install":[{"cmd":"pip install acachecontrol","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Core dependency for asynchronous HTTP requests, updated to >=3.10.2 in v0.3.6.","package":"aiohttp","optional":false}],"imports":[{"symbol":"AsyncCache","correct":"from acachecontrol import AsyncCache"},{"symbol":"AsyncCacheControl","correct":"from acachecontrol import AsyncCacheControl"}],"quickstart":{"code":"import asyncio\nfrom acachecontrol import AsyncCache, AsyncCacheControl\n\nasync def main():\n    # Initialize AsyncCache, default configuration uses an in-memory dictionary\n    cache = AsyncCache()\n\n    # Use AsyncCacheControl to wrap an aiohttp ClientSession\n    async with AsyncCacheControl(cache=cache) as cached_session:\n        print(\"First request (should fetch):\")\n        async with cached_session.get('http://example.com') as resp:\n            text_data = await resp.text()\n            print(f\"Status: {resp.status}, From cache: {getattr(resp, 'from_cache', False)}\")\n            # print(text_data[:100]) # Print first 100 chars for brevity\n\n        print(\"\\nSecond request (should be cached):\")\n        async with cached_session.get('http://example.com') as resp:\n            text_data = await resp.text()\n            print(f\"Status: {resp.status}, From cache: {getattr(resp, 'from_cache', False)}\")\n            # print(text_data[:100]) # Print first 100 chars for brevity\n\nif __name__ == '__main__':\n    asyncio.run(main())\n","lang":"python","description":"This quickstart demonstrates how to use `acachecontrol` to cache HTTP GET requests made with `aiohttp`. The first request to `http://example.com` will fetch the content, and subsequent requests within the cache's validity period will be served from the cache without making a new network request to the origin server. The `from_cache` attribute on the response indicates if it was served from cache. You can configure `AsyncCache` with different backends if needed."},"warnings":[{"fix":"Ensure `aiohttp` is installed with version `>=3.10.2`. Update `aiohttp` if an older version is present: `pip install --upgrade aiohttp`.","message":"Version 0.3.6 updated the minimum required `aiohttp` version to `>=3.10.2`. Using `acachecontrol` with older `aiohttp` versions may lead to compatibility issues or errors.","severity":"breaking","affected_versions":"<0.3.6"},{"fix":"Refer to the `CustomCacheBackend` example in the official documentation or GitHub README for a complete list of required methods and their expected behavior.","message":"When implementing a custom cache backend for `AsyncCache`, it must fully adhere to the `OrderedDict` interface, including methods like `__contains__`, `__len__`, `__getitem__`, `__setitem__`, `get`, `pop`, `popitem`, and `move_to_end`. Incomplete implementations can cause unexpected runtime errors or incorrect caching behavior.","severity":"gotcha","affected_versions":"All versions supporting custom backends"},{"fix":"Upgrade to `acachecontrol>=0.3.4` to handle non-numeric `max-age` values gracefully. Additionally, ensure upstream services provide valid integer values for `max-age`.","message":"Versions of `acachecontrol` prior to `0.3.4` could fail if a `Cache-Control` header contained a `max-age` directive that was not a valid number. This would result in parsing errors and prevent caching.","severity":"gotcha","affected_versions":"<0.3.4"},{"fix":"Upgrade to `acachecontrol>=0.3.3` to resolve this issue. Consider explicitly setting timeouts on `aiohttp.ClientSession` for fine-grained control if needed.","message":"A default request timeout issue was fixed in version `0.3.3`. Users of older versions might experience requests hanging or unexpectedly timing out under certain conditions.","severity":"gotcha","affected_versions":"<0.3.3"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[{"fix":"Install the package using pip: 'pip install acachecontrol'.","cause":"The 'acachecontrol' package is not installed in the Python environment.","error":"ModuleNotFoundError: No module named 'acachecontrol'"},{"fix":"Ensure you are using the correct import statement: 'from acachecontrol import AsyncCache, AsyncCacheControl'.","cause":"The 'AsyncCache' class is not available in the 'acachecontrol' module.","error":"ImportError: cannot import name 'AsyncCache' from 'acachecontrol'"},{"fix":"Check if the response or cache object is 'None' before accessing its elements.","cause":"Attempting to access elements of a 'None' object, possibly due to a failed request or uninitialized cache.","error":"TypeError: 'NoneType' object is not subscriptable"},{"fix":"from acachecontrol import AsyncCache, AsyncCacheControl\ncache_instance = AsyncCache()\nsession = AsyncCacheControl(cache=cache_instance)","cause":"The AsyncCacheControl class requires an instance of AsyncCache (or a compatible cache object) to be passed via the 'cache' keyword argument during initialization.","error":"TypeError: AsyncCacheControl.__init__ missing 1 required positional argument: 'cache'"},{"fix":"from acachecontrol import AsyncCacheControl","cause":"The AsyncCacheControl class was used without being imported first from the 'acachecontrol' library.","error":"NameError: name 'AsyncCacheControl' is not defined"}]}