| 1 |
Built-in Cache Backends |
| 2 |
----------------------- |
| 3 |
|
| 4 |
.. _basecache: |
| 5 |
|
| 6 |
BaseCache |
| 7 |
````````` |
| 8 |
|
| 9 |
.. currentmodule:: flask_caching.backends.base |
| 10 |
.. py:class:: BaseCache |
| 11 |
:no-index-entry: |
| 12 |
|
| 13 |
Baseclass for all the cache backends listed below. It isn't meant to be |
| 14 |
used directly, but you can subclass it to implement your own |
| 15 |
:ref:`custom cache backend <custom-cache-backends>`. |
| 16 |
|
| 17 |
|
| 18 |
.. _nullcache: |
| 19 |
|
| 20 |
NullCache |
| 21 |
````````` |
| 22 |
|
| 23 |
.. currentmodule:: flask_caching.backends.nullcache |
| 24 |
.. py:class:: NullCache |
| 25 |
:no-index-entry: |
| 26 |
|
| 27 |
Set ``CACHE_TYPE`` to ``NullCache`` to use this type. |
| 28 |
|
| 29 |
Cache that doesn't cache |
| 30 |
|
| 31 |
- CACHE_DEFAULT_TIMEOUT |
| 32 |
|
| 33 |
.. versionchanged:: 2.5.0 |
| 34 |
Removed the deprecated old name in favour of just using the class name. |
| 35 |
|
| 36 |
|
| 37 |
.. _simplecache: |
| 38 |
|
| 39 |
SimpleCache |
| 40 |
``````````` |
| 41 |
|
| 42 |
.. currentmodule:: flask_caching.backends.simplecache |
| 43 |
.. py:class:: SimpleCache |
| 44 |
:no-index-entry: |
| 45 |
|
| 46 |
Set ``CACHE_TYPE`` to ``SimpleCache`` to use this type. |
| 47 |
|
| 48 |
Uses a local python dictionary for caching. All operations are protected by |
| 49 |
a lock, making it thread-safe. |
| 50 |
|
| 51 |
Relevant configuration values |
| 52 |
|
| 53 |
- CACHE_DEFAULT_TIMEOUT |
| 54 |
- CACHE_IGNORE_ERRORS |
| 55 |
- CACHE_THRESHOLD |
| 56 |
|
| 57 |
.. versionchanged:: 2.5.0 |
| 58 |
Removed the deprecated old name in favour of just using the class name. |
| 59 |
|
| 60 |
|
| 61 |
.. _filesystemcache: |
| 62 |
|
| 63 |
FileSystemCache |
| 64 |
``````````````` |
| 65 |
|
| 66 |
.. currentmodule:: flask_caching.backends.filesystemcache |
| 67 |
.. py:class:: FileSystemCache |
| 68 |
:no-index-entry: |
| 69 |
|
| 70 |
Set ``CACHE_TYPE`` to ``FileSystemCache`` to use this type. |
| 71 |
|
| 72 |
Uses the filesystem to store cached values |
| 73 |
|
| 74 |
- CACHE_DEFAULT_TIMEOUT |
| 75 |
- CACHE_IGNORE_ERRORS |
| 76 |
- CACHE_DIR |
| 77 |
- CACHE_THRESHOLD |
| 78 |
- CACHE_OPTIONS |
| 79 |
|
| 80 |
There is a single valid entry in CACHE_OPTIONS: *mode*, which should be a 3 digit |
| 81 |
linux-style permissions octal mode. |
| 82 |
|
| 83 |
.. versionchanged:: 2.5.0 |
| 84 |
Removed the deprecated old name in favour of just using the class name. |
| 85 |
|
| 86 |
|
| 87 |
.. _rediscache: |
| 88 |
|
| 89 |
RedisCache |
| 90 |
`````````` |
| 91 |
|
| 92 |
.. currentmodule:: flask_caching.backends.rediscache |
| 93 |
.. py:class:: RedisCache |
| 94 |
:no-index-entry: |
| 95 |
|
| 96 |
Set ``CACHE_TYPE`` to ``RedisCache`` to use this type. |
| 97 |
|
| 98 |
- CACHE_DEFAULT_TIMEOUT |
| 99 |
- CACHE_IGNORE_ERRORS |
| 100 |
- CACHE_KEY_PREFIX |
| 101 |
- CACHE_OPTIONS |
| 102 |
- CACHE_REDIS_HOST |
| 103 |
- CACHE_REDIS_PORT |
| 104 |
- CACHE_REDIS_PASSWORD |
| 105 |
- CACHE_REDIS_DB |
| 106 |
- CACHE_REDIS_URL |
| 107 |
|
| 108 |
Entries in CACHE_OPTIONS are passed to the redis client as ``**kwargs`` |
| 109 |
|
| 110 |
``CACHE_REDIS_HOST`` also accepts an already created Redis client instead of a |
| 111 |
host name. Use it to share one connection pool with the rest of the |
| 112 |
application, see :ref:`sharing-a-redis-client`. |
| 113 |
|
| 114 |
.. versionchanged:: 2.5.0 |
| 115 |
Removed the deprecated old name in favour of just using the class name. |
| 116 |
|
| 117 |
|
| 118 |
.. _redissentinelcache: |
| 119 |
|
| 120 |
RedisSentinelCache |
| 121 |
`````````````````` |
| 122 |
|
| 123 |
.. py:class:: RedisSentinelCache |
| 124 |
:no-index-entry: |
| 125 |
|
| 126 |
Set ``CACHE_TYPE`` to ``RedisSentinel`` to use this type. |
| 127 |
|
| 128 |
- CACHE_IGNORE_ERRORS |
| 129 |
- CACHE_KEY_PREFIX |
| 130 |
- CACHE_REDIS_SENTINELS |
| 131 |
- CACHE_REDIS_SENTINEL_MASTER |
| 132 |
- CACHE_REDIS_PASSWORD |
| 133 |
- CACHE_REDIS_SENTINEL_PASSWORD |
| 134 |
- CACHE_REDIS_DB |
| 135 |
|
| 136 |
Entries in CACHE_OPTIONS are passed to the redis client as ``**kwargs`` |
| 137 |
|
| 138 |
.. versionchanged:: 2.5.0 |
| 139 |
Removed the deprecated old name in favour of just using the class name. |
| 140 |
|
| 141 |
|
| 142 |
.. _redisclustercache: |
| 143 |
|
| 144 |
RedisClusterCache |
| 145 |
`````````````````` |
| 146 |
|
| 147 |
.. py:class:: RedisClusterCache |
| 148 |
:no-index-entry: |
| 149 |
|
| 150 |
Set ``CACHE_TYPE`` to ``RedisClusterCache`` to use this type. |
| 151 |
|
| 152 |
- CACHE_IGNORE_ERRORS |
| 153 |
- CACHE_KEY_PREFIX |
| 154 |
- CACHE_REDIS_CLUSTER |
| 155 |
- CACHE_REDIS_PASSWORD |
| 156 |
- CACHE_REDIS_URL |
| 157 |
|
| 158 |
Entries in CACHE_OPTIONS are passed to the redis client as ``**kwargs`` |
| 159 |
|
| 160 |
.. versionchanged:: 2.5.0 |
| 161 |
Removed the deprecated old name in favour of just using the class name. |
| 162 |
|
| 163 |
|
| 164 |
.. _memcachedcache: |
| 165 |
|
| 166 |
MemcachedCache |
| 167 |
`````````````` |
| 168 |
|
| 169 |
.. currentmodule:: flask_caching.backends.memcache |
| 170 |
.. py:class:: MemcachedCache |
| 171 |
:no-index-entry: |
| 172 |
|
| 173 |
Set ``CACHE_TYPE`` to ``MemcachedCache`` to use this type. |
| 174 |
|
| 175 |
Uses a memcached server as a backend. Supports either pylibmc or memcache or |
| 176 |
google app engine memcache library. |
| 177 |
|
| 178 |
Relevant configuration values |
| 179 |
|
| 180 |
- CACHE_DEFAULT_TIMEOUT |
| 181 |
- CACHE_IGNORE_ERRORS |
| 182 |
- CACHE_KEY_PREFIX |
| 183 |
- CACHE_MEMCACHED_SERVERS |
| 184 |
- CACHE_OPTIONS |
| 185 |
|
| 186 |
``MemcachedCache`` only accepts ``pool_size`` and ``pool_blocking`` in the |
| 187 |
``CACHE_OPTIONS``. |
| 188 |
|
| 189 |
.. versionadded:: 2.5.0 |
| 190 |
``pool_size`` and ``pool_blocking`` options. |
| 191 |
|
| 192 |
.. note:: Flask-Caching does not pass additional configuration options |
| 193 |
to memcached backends. To add additional configuration to these caches, |
| 194 |
directly set the configuration options on the object after instantiation:: |
| 195 |
|
| 196 |
from flask_caching import Cache |
| 197 |
cache = Cache() |
| 198 |
|
| 199 |
# Can't configure the client yet... |
| 200 |
cache.init_app(flask_app, {"CACHE_TYPE": "MemcachedCache"}) |
| 201 |
|
| 202 |
# Break convention and set options on the _client object |
| 203 |
# directly. For pylibmc behaviors: |
| 204 |
cache.cache._client.behaviors({"tcp_nodelay": True}) |
| 205 |
|
| 206 |
Alternatively, see :ref:`Custom Cache Backends <custom-cache-backends>`. |
| 207 |
|
| 208 |
.. versionchanged:: 2.5.0 |
| 209 |
Removed the deprecated old name in favour of just using the class name. |
| 210 |
|
| 211 |
|
| 212 |
.. _saslmemcachedcache: |
| 213 |
|
| 214 |
SASLMemcachedCache |
| 215 |
`````````````````` |
| 216 |
|
| 217 |
.. py:class:: SASLMemcachedCache |
| 218 |
:no-index-entry: |
| 219 |
|
| 220 |
Set ``CACHE_TYPE`` to ``SASLMemcachedCache`` to use this type. |
| 221 |
|
| 222 |
Uses a memcached server as a backend. Intended to be used with a SASL enabled |
| 223 |
connection to the memcached server. pylibmc is required and SASL must be supported |
| 224 |
by libmemcached. |
| 225 |
|
| 226 |
Relevant configuration values |
| 227 |
|
| 228 |
- CACHE_DEFAULT_TIMEOUT |
| 229 |
- CACHE_IGNORE_ERRORS |
| 230 |
- CACHE_KEY_PREFIX |
| 231 |
- CACHE_OPTIONS |
| 232 |
- CACHE_MEMCACHED_SERVERS |
| 233 |
- CACHE_MEMCACHED_USERNAME |
| 234 |
- CACHE_MEMCACHED_PASSWORD |
| 235 |
|
| 236 |
.. note:: Like ``MemcachedCache``, ``pool_size``/``pool_blocking`` in |
| 237 |
``CACHE_OPTIONS`` configure the connection pool. Unlike |
| 238 |
``MemcachedCache``, any other ``CACHE_OPTIONS`` entry is also |
| 239 |
accepted and forwarded as ``**kwargs`` to ``pylibmc.Client``. |
| 240 |
|
| 241 |
.. versionadded:: 0.10 |
| 242 |
|
| 243 |
.. versionchanged:: 2.5.0 |
| 244 |
Removed the deprecated old name in favour of just using the class name. |
| 245 |
|
| 246 |
.. versionchanged:: 2.5.0 |
| 247 |
``CACHE_IGNORE_ERRORS`` is now honoured by this backend. |
| 248 |
|
| 249 |
|
| 250 |
.. _spreadsaslmemcachedcache: |
| 251 |
|
| 252 |
SpreadSASLMemcachedCache |
| 253 |
```````````````````````` |
| 254 |
|
| 255 |
.. py:class:: SpreadSASLMemcachedCache |
| 256 |
:no-index-entry: |
| 257 |
|
| 258 |
Set ``CACHE_TYPE`` to ``SpreadSASLMemcachedCache`` to use this type. |
| 259 |
|
| 260 |
Same as SASLMemcachedCache however, it has the ability to spread value across |
| 261 |
multiple keys if it is bigger than the memcached threshold which by |
| 262 |
default is 1M. Uses pickle. |
| 263 |
|
| 264 |
.. versionadded:: 0.11 |
| 265 |
|
| 266 |
.. versionchanged:: 1.1.0 |
| 267 |
Renamed ``spreadsaslmemcachedcache`` to ``spreadsaslmemcached`` for |
| 268 |
the sake of consistency. |
| 269 |
|
| 270 |
.. versionchanged:: 2.5.0 |
| 271 |
Removed the deprecated old name in favour of just using the class name. |