| 1 |
.. aiocache documentation master file, created by |
| 2 |
sphinx-quickstart on Sat Oct 1 16:53:45 2016. |
| 3 |
You can adapt this file completely to your liking, but it should at least |
| 4 |
contain the root `toctree` directive. |
| 5 |
|
| 6 |
Welcome to aiocache's documentation! |
| 7 |
==================================== |
| 8 |
|
| 9 |
|
| 10 |
Installing |
| 11 |
---------- |
| 12 |
|
| 13 |
- ``pip install aiocache`` |
| 14 |
- ``pip install aiocache[redis]`` |
| 15 |
- ``pip install aiocache[memcached]`` |
| 16 |
- ``pip install aiocache[redis,memcached]`` |
| 17 |
|
| 18 |
|
| 19 |
Usage |
| 20 |
----- |
| 21 |
|
| 22 |
Using a cache is as simple as |
| 23 |
|
| 24 |
.. code-block:: python |
| 25 |
|
| 26 |
>>> import asyncio |
| 27 |
>>> from aiocache import Cache |
| 28 |
>>> cache = Cache() |
| 29 |
>>> with asyncio.Runner() as runner: |
| 30 |
>>> runner.run(cache.set("key", "value")) |
| 31 |
True |
| 32 |
>>> runner.run(cache.get("key")) |
| 33 |
'value' |
| 34 |
|
| 35 |
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: |
| 36 |
|
| 37 |
- ``add``: Only adds key/value if key does not exist. Otherwise raises ValueError. |
| 38 |
- ``get``: Retrieve value identified by key. |
| 39 |
- ``set``: Sets key/value. |
| 40 |
- ``multi_get``: Retrieves multiple key/values. |
| 41 |
- ``multi_set``: Sets multiple key/values. |
| 42 |
- ``exists``: Returns True if key exists False otherwise. |
| 43 |
- ``increment``: Increment the value stored in the given key. |
| 44 |
- ``delete``: Deletes key and returns number of deleted items. |
| 45 |
- ``clear``: Clears the items stored. |
| 46 |
- ``raw``: Executes the specified command using the underlying client. |
| 47 |
|
| 48 |
|
| 49 |
You can also setup cache aliases like in Django settings: |
| 50 |
|
| 51 |
.. literalinclude:: ../examples/cached_alias_config.py |
| 52 |
:language: python |
| 53 |
:linenos: |
| 54 |
:emphasize-lines: 6-26 |
| 55 |
|
| 56 |
|
| 57 |
In `examples folder <https://github.com/argaen/aiocache/tree/master/examples>`_ you can check different use cases: |
| 58 |
|
| 59 |
- `Sanic, Aiohttp and Tornado <https://github.com/argaen/aiocache/tree/master/examples/frameworks>`_ |
| 60 |
- `Python object in Redis <https://github.com/argaen/aiocache/blob/master/examples/python_object.py>`_ |
| 61 |
- `Custom serializer for compressing data <https://github.com/argaen/aiocache/blob/master/examples/serializer_class.py>`_ |
| 62 |
- `TimingPlugin and HitMissRatioPlugin demos <https://github.com/argaen/aiocache/blob/master/examples/plugins.py>`_ |
| 63 |
- `Using marshmallow as a serializer <https://github.com/argaen/aiocache/blob/master/examples/marshmallow_serializer_class.py>`_ |
| 64 |
- `Using cached decorator <https://github.com/argaen/aiocache/blob/master/examples/cached_decorator.py>`_. |
| 65 |
- `Using multi_cached decorator <https://github.com/argaen/aiocache/blob/master/examples/multicached_decorator.py>`_. |
| 66 |
|
| 67 |
|
| 68 |
Contents |
| 69 |
-------- |
| 70 |
|
| 71 |
.. toctree:: |
| 72 |
|
| 73 |
caches |
| 74 |
serializers |
| 75 |
plugins |
| 76 |
configuration |
| 77 |
decorators |
| 78 |
locking |
| 79 |
testing |
| 80 |
|
| 81 |
Indices and tables |
| 82 |
================== |
| 83 |
|
| 84 |
* :ref:`genindex` |
| 85 |
* :ref:`modindex` |
| 86 |
* :ref:`search` |