MCPcopy Index your code
hub / github.com/django/django / CacheMiddleware

Class CacheMiddleware

django/middleware/cache.py:205–237  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

203
204
205class 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

Callers 4

test_constructorMethod · 0.90
test_middlewareMethod · 0.90
test_per_threadMethod · 0.90

Calls

no outgoing calls

Tested by 4

test_constructorMethod · 0.72
test_middlewareMethod · 0.72
test_per_threadMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…