Asynchronous redis cache
Project description
An asynchronous cache implementation with multiple backends for asyncio. Used django-redis-cache and redis-simple-cache as inspiration for the initial structure.
Disclaimer: The code is still in alpha version so new versions may introduce breaking changes. Once version 1.0 is reached, deprecation policy will be introduced.
Supported backends:
This libraries aims for simplicity over specialization. It provides a common interface for all caches which allows to store any python object. The operations supported by all backends are:
add
exists
get
set
multi_get
multi_set
delete
Usage
Install the package with pip install aiocache.
cached decorator
import asyncio
from collections import namedtuple
from aiocache import cached, RedisCache
from aiocache.serializers import PickleSerializer
Result = namedtuple('Result', "content, status")
@cached(ttl=10)
async def async_main():
print("First ASYNC non cached call...")
await asyncio.sleep(1)
return Result("content", 200)
if __name__ == "__main__":
loop = asyncio.get_event_loop()
print(loop.run_until_complete(async_main()))
print(loop.run_until_complete(async_main()))
print(loop.run_until_complete(async_main()))
print(loop.run_until_complete(async_main()))
The decorator by default will use the SimpleMemoryCache backend and the DefaultSerializer. If you want to use a different backend, you can call it with cached(ttl=10, backend=RedisCache). Also, if you want to use a specific serializer just use cached(ttl=10, serializer=DefaultSerializer())
Documentation
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
File details
Details for the file aiocache-0.1.1.tar.gz
.
File metadata
- Download URL: aiocache-0.1.1.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84b29e2f0494dfa148a9181bdf015bb336e23fde348cbdeb8bb4629d3f9f582f |
|
MD5 | 1cdc72b6637ddd836ca03ed91ab18fa7 |
|
BLAKE2b-256 | 47f4dac91ab3135dd864b46d2f04ee5d96bc3f6d56e35394a31e2299eb9fd1ed |