| 1 |
.. _configuration: |
| 2 |
|
| 3 |
Configuration |
| 4 |
============= |
| 5 |
|
| 6 |
The caches module allows to setup cache configurations and then use them either using an alias or retrieving the config explicitly. To set the config, call ``caches.set_config``: |
| 7 |
|
| 8 |
.. automethod:: aiocache.caches.set_config |
| 9 |
|
| 10 |
To retrieve a copy of the current config, you can use ``caches.get_config`` or ``caches.get_alias_config`` for an alias config. |
| 11 |
|
| 12 |
|
| 13 |
Next snippet shows an example usage: |
| 14 |
|
| 15 |
.. literalinclude:: ../examples/cached_alias_config.py |
| 16 |
:language: python |
| 17 |
:linenos: |
| 18 |
:emphasize-lines: 6-26 |
| 19 |
|
| 20 |
When you do ``caches.get('alias_name')``, the cache instance is built lazily the first time. Next accesses will return the **same** instance. If instead of reusing the same instance, you need a new one every time, use ``caches.create('alias_name')``. One of the advantages of ``caches.create`` is that it accepts extra args that then are passed to the cache constructor. This way you can override args like namespace, endpoint, etc. |
| 21 |
|
| 22 |
.. automethod:: aiocache.caches.add |
| 23 |
|
| 24 |
.. automethod:: aiocache.caches.get |
| 25 |
|
| 26 |
.. automethod:: aiocache.caches.create |