Skip to content

Latest commit

 

History

History
91 lines (65 loc) · 3.2 KB

index.rst

File metadata and controls

91 lines (65 loc) · 3.2 KB

Welcome to aiocache's documentation!

Installing

pip install aiocache

If you don't need redis or memcached support, you can install as follows:

AIOCACHE_REDIS=no pip install aiocache       # Don't install redis client (aioredis)
AIOCACHE_MEMCACHED=no pip install aiocache   # Don't install memcached client (aiomcache)

Usage

Using a cache is as simple as

>>> import asyncio
>>> loop = asyncio.get_event_loop()
>>> from aiocache import SimpleMemoryCache
>>> cache = SimpleMemoryCache()
>>> loop.run_until_complete(cache.set('key', 'value'))
True
>>> loop.run_until_complete(cache.get('key'))
'value'

Here we are using the :ref:`simplememorycache` but you can use any other listed in :ref:`caches`. All caches contain the same minimum interface which consists on 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.

You can also setup cache aliases like in Django settings:

.. literalinclude:: ../examples/cached_alias_config.py
  :language: python
  :linenos:
  :emphasize-lines: 6-26


In examples folder you can check different use cases:

Contents

.. toctree::

  caches
  serializers
  plugins
  configuration
  decorators
  testing

Indices and tables