MCPcopy Create free account
hub / github.com/alephdata/aleph / enable_cache

Function enable_cache

aleph/views/context.py:42–63  ·  view source on GitHub ↗

Enable caching in the context of a view. If desired, instructions on the cache parameters can be included, such as if the data is fit for public caches (default: no, vary_user) and what values to include in the generation of an etag.

(vary_user=True, vary=None)

Source from the content-addressed store, hash-verified

40
41
42def enable_cache(vary_user=True, vary=None):
43 """Enable caching in the context of a view.
44
45 If desired, instructions on the cache parameters can be included, such as
46 if the data is fit for public caches (default: no, vary_user) and what
47 values to include in the generation of an etag.
48 """
49 if not SETTINGS.CACHE:
50 return
51
52 request._http_cache = True
53 request._http_revalidate = vary is not None
54 args = sorted(set(request.args.items()))
55 cache_parts = [args, vary, request._app_locale]
56
57 if vary_user and request.authz.logged_in:
58 cache_parts.extend((request.authz.roles))
59 request._http_private = True
60
61 request._http_etag = hash_data(cache_parts)
62 if request._http_etag in request.if_none_match:
63 raise NotModified()
64
65
66def _get_remote_ip():

Callers 5

openapiFunction · 0.90
statisticsFunction · 0.90
sitemapFunction · 0.90
viewFunction · 0.90
tagsFunction · 0.90

Calls 2

NotModifiedClass · 0.85
itemsMethod · 0.45

Tested by

no test coverage detected