{"id":1309,"library":"aiocache","title":"AioCache","description":"aiocache is a multi-backend asynchronous cache library for Python, providing support for Redis, Memcached, and in-memory caching. It integrates well with asyncio applications. The current version is 0.12.3, and it receives regular patch updates, with minor versions released periodically.","status":"active","version":"0.12.3","language":"en","source_language":"en","source_url":"https://github.com/aio-libs/aiocache","tags":["asyncio","cache","redis","memcached","memory","decorator"],"install":[{"cmd":"pip install aiocache[redis,memcached]","lang":"bash","label":"Install with Redis and Memcached backends"},{"cmd":"pip install aiocache","lang":"bash","label":"Install base (in-memory cache only)"}],"dependencies":[{"reason":"Required for the Redis backend. Install with `pip install aiocache[redis]`.","package":"redis","optional":true},{"reason":"Required for the Memcached backend. Install with `pip install aiocache[memcached]`.","package":"aiomcache","optional":true}],"imports":[{"symbol":"Cache","correct":"from aiocache import Cache"},{"symbol":"cached","correct":"from aiocache.cached import cached"},{"note":"As of v0.12.0, aiocache migrated from aioredis to the official redis library.","wrong":"from aiocache.backends.aioredis import RedisCache","symbol":"RedisCache","correct":"from aiocache.backends.redis import RedisCache"},{"symbol":"MemcachedCache","correct":"from aiocache.backends.memcached import MemcachedCache"},{"symbol":"SimpleMemoryCache","correct":"from aiocache.backends.memory import SimpleMemoryCache"}],"quickstart":{"code":"import asyncio\nimport os\nfrom aiocache import Cache\n\nasync def main():\n    # Configure Redis cache using environment variables or fallbacks\n    redis_endpoint = os.environ.get('REDIS_ENDPOINT', 'localhost')\n    redis_port = int(os.environ.get('REDIS_PORT', '6379'))\n\n    # Use async with for proper resource management (auto-closes connection)\n    async with Cache(Cache.REDIS, endpoint=redis_endpoint, port=redis_port) as cache:\n        key = \"my_async_key\"\n        value = \"hello from aiocache\"\n        ttl_seconds = 60\n\n        print(f\"Setting '{key}' = '{value}' with TTL {ttl_seconds}s\")\n        await cache.set(key, value, ttl=ttl_seconds)\n\n        retrieved_value = await cache.get(key)\n        print(f\"Retrieved value for '{key}': {retrieved_value}\")\n\n        if retrieved_value == value:\n            print(\"Value successfully cached and retrieved!\")\n        else:\n            print(\"Cache retrieval failed.\")\n\nif __name__ == '__main__':\n    # Ensure Redis server is running at REDIS_ENDPOINT:REDIS_PORT\n    # e.g., docker run --name some-redis -p 6379:6379 -d redis\n    asyncio.run(main())","lang":"python","description":"This quickstart demonstrates how to initialize and use the Redis backend with `aiocache` using the `Cache` factory. It leverages `async with` for automatic connection management and shows setting and getting a key-value pair. Ensure a Redis server is running and accessible."},"warnings":[{"fix":"Ensure `pip install aiocache[redis]` is used. Update any imports or direct usage of `aioredis` client methods to align with the `redis` library's API. For `Cache` factory, connection parameters might need review.","message":"Breaking change: aiocache migrated from `aioredis` to the official `redis` Python library. Existing code using `aioredis` specific APIs or directly importing `aioredis` backend classes will break.","severity":"breaking","affected_versions":"0.12.0+"},{"fix":"If your application relied on `SimpleMemoryBackend` instances sharing a global state, you will need to refactor to pass a single `SimpleMemoryCache` instance around or adapt to its new instance-scoped behavior.","message":"Breaking change: The `SimpleMemoryBackend` (and `SimpleMemoryCache`) is no longer a global singleton. Each instance now has its own isolated cache.","severity":"breaking","affected_versions":"0.12.0+"},{"fix":"Remove the `loop` parameter from all `aiocache` calls. `aiocache` now relies on `asyncio`'s default event loop mechanisms.","message":"Deprecated `loop` parameters have been removed from most methods and constructors, including `Cache.create()`. Passing an explicit `loop` will now raise an error.","severity":"deprecated","affected_versions":"0.12.0+"},{"fix":"Do not rely on `aiocache` for strict type checking until `v1.0`. Temporarily, you might need to use `# type: ignore` for specific `aiocache` related lines if your linter complains.","message":"Typing support was removed in `v0.12.1` due to issues and is planned to be re-introduced in `v1.0`. Users expecting comprehensive type hints will find them missing or causing unresolvable errors.","severity":"gotcha","affected_versions":"0.12.1+ (until v1.0)"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}