Welcome to aiocache’s documentation!¶
Installing¶
pip install aiocachepip install aiocache[redis]pip install aiocache[memcached]pip install aiocache[redis,memcached]
Usage¶
Using a cache is as simple as
>>> import asyncio
>>> from aiocache import SimpleMemoryCache
>>> cache = SimpleMemoryCache()
>>> with asyncio.Runner() as runner:
>>> runner.run(cache.set("key", "value"))
True
>>> runner.run(cache.get("key"))
'value'
Here we are using the SimpleMemoryCache but you can use any other supported backends as listed in Caches. All caches contain the same minimum interface which consists of the following functions:
add: Only adds key/value if key does not exist. Otherwise raises ValueError.get: Retrieve value identified by key.set: Sets key/value.multi_get: Retrieves multiple key/values.multi_set: Sets multiple key/values.exists: Returns True if key exists False otherwise.increment: Increment the value stored in the given key.delete: Deletes key and returns number of deleted items.clear: Clears the items stored.raw: Executes the specified command using the underlying client.
See the examples folder for different use cases:
Contents¶
- Caches
- Third-party caches
- Serializers
- Plugins
- BasePlugin
BasePluginBasePlugin.add_hook()BasePlugin.do_nothing()BasePlugin.post_add()BasePlugin.post_clear()BasePlugin.post_delete()BasePlugin.post_exists()BasePlugin.post_expire()BasePlugin.post_get()BasePlugin.post_increment()BasePlugin.post_multi_get()BasePlugin.post_multi_set()BasePlugin.post_raw()BasePlugin.post_set()BasePlugin.pre_add()BasePlugin.pre_clear()BasePlugin.pre_delete()BasePlugin.pre_exists()BasePlugin.pre_expire()BasePlugin.pre_get()BasePlugin.pre_increment()BasePlugin.pre_multi_get()BasePlugin.pre_multi_set()BasePlugin.pre_raw()BasePlugin.pre_set()
- TimingPlugin
TimingPluginTimingPlugin.post_add()TimingPlugin.post_clear()TimingPlugin.post_delete()TimingPlugin.post_exists()TimingPlugin.post_expire()TimingPlugin.post_get()TimingPlugin.post_increment()TimingPlugin.post_multi_get()TimingPlugin.post_multi_set()TimingPlugin.post_raw()TimingPlugin.post_set()TimingPlugin.save_time()
- HitMissRatioPlugin
- BasePlugin
- Decorators
- Locking
- Testing
- Migrating from v0.x to v1