Cache middleware that provides basic behavior for many simple sites. Also used as the hook point for the cache decorator, which is generated using the decorator-from-middleware utility.
| 203 | |
| 204 | |
| 205 | class CacheMiddleware(UpdateCacheMiddleware, FetchFromCacheMiddleware): |
| 206 | """ |
| 207 | Cache middleware that provides basic behavior for many simple sites. |
| 208 | |
| 209 | Also used as the hook point for the cache decorator, which is generated |
| 210 | using the decorator-from-middleware utility. |
| 211 | """ |
| 212 | |
| 213 | def __init__(self, get_response, cache_timeout=None, page_timeout=None, **kwargs): |
| 214 | super().__init__(get_response) |
| 215 | # We need to differentiate between "provided, but using default value", |
| 216 | # and "not provided". If the value is provided using a default, then |
| 217 | # we fall back to system defaults. If it is not provided at all, |
| 218 | # we need to use middleware defaults. |
| 219 | |
| 220 | try: |
| 221 | key_prefix = kwargs["key_prefix"] |
| 222 | if key_prefix is None: |
| 223 | key_prefix = "" |
| 224 | self.key_prefix = key_prefix |
| 225 | except KeyError: |
| 226 | pass |
| 227 | try: |
| 228 | cache_alias = kwargs["cache_alias"] |
| 229 | if cache_alias is None: |
| 230 | cache_alias = DEFAULT_CACHE_ALIAS |
| 231 | self.cache_alias = cache_alias |
| 232 | except KeyError: |
| 233 | pass |
| 234 | |
| 235 | if cache_timeout is not None: |
| 236 | self.cache_timeout = cache_timeout |
| 237 | self.page_timeout = page_timeout |
no outgoing calls
searching dependent graphs…