adhocracy_core.caching package

Adapter and helper functions to set the http response caching headers.

set_cache_header(view: <built-in function callable>)[source]

Decorator for view to set http cache headers of the response.

register_cache_strategy(strategy_adapter: <InterfaceClass adhocracy_core.interfaces.IHTTPCacheStrategy>, iresource: <InterfaceClass zope.interface.interfaces.IInterface>, registry: pyramid.registry.Registry, view_or_method: str)[source]

Register a cache strategy for a specific context interface and view.

class HTTPCacheStrategyBaseAdapter(context, request)[source]

Bases: object

Basic cache strategy adapter a to set http cache headers.

You can register a cache strategy for a specific context and view with adhocracy_core.caching.register_http_cache_strategy_adapter().

For more information about caching headers read: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

Initialize self.

browser_max_age = 0

Time (in seconds) to cache the response in the browser or caching proxy. Adds a “Cache-Control: max-age=<value>” header.

proxy_max_age = 0

Time (in seconds) to cache the response in the caching proxy. Adds a “Cache-Control: s-maxage=<value>” header to the response.

last_modified = False

Adds a “Last-Modified” header to the response and turns on “304 Not Modified” responses for “If-Modified-Since” conditional requests.

etags = ()

Tuple of etag functions (accepting context and request, return str) to build the Etag header. Turns on “304 Not Modified” responses for “If-None-Match” conditional requests.

vary = ()

Tuple of names of HTTP headers in the request that must match for a caching proxy to return a cached response.

context = None

The view context.

request = None

The request to set the cache headers.

check_conditional_request()[source]

Check if conditional_request and raise 304 Error if needed.

raise pyramid.httpexceptions.HTTPNotModified:
if conditional request and context is not modified.
set_cache_headers_for_mode(mode: adhocracy_core.interfaces.HTTPCacheMode)[source]

Set response cache headers according to HTTPCacheMode.

set_debug_info(mode: adhocracy_core.interfaces.HTTPCacheMode)[source]

Set debug info.

set_do_not_cache()[source]

Disable caching.

set_cache_control_without_proxy()[source]

Set cache control without proxy.

set_cache_control_with_proxy()[source]

Set cache control with proxy.

set_last_modified()[source]

Set last_modified attribute.

set_etag()[source]

Set etag.

set_vary()[source]

Set vary attribute.

etag_backrefs(context: <InterfaceClass adhocracy_core.interfaces.IResource>, request: <InterfaceClass pyramid.interfaces.IRequest>) → str[source]

Return changed backrefs counter value.

etag_descendants(context: <InterfaceClass adhocracy_core.interfaces.IResource>, request: <InterfaceClass pyramid.interfaces.IRequest>) → str[source]

Return changed descendants counter value.

etag_modified(context: <InterfaceClass adhocracy_core.interfaces.IResource>, request: <InterfaceClass pyramid.interfaces.IRequest>) → str[source]

Return modification date.

etag_userid(context: <InterfaceClass adhocracy_core.interfaces.IResource>, request: <InterfaceClass pyramid.interfaces.IRequest>) → str[source]

Return userid.

etag_blocked(context: <InterfaceClass adhocracy_core.interfaces.IResource>, request: <InterfaceClass pyramid.interfaces.IRequest>) → str[source]

Return resource blocked status.

class HTTPCacheStrategyWeakAdapter(context, request)[source]

Bases: adhocracy_core.caching.HTTPCacheStrategyBaseAdapter

Weak strategy adapter to set http cache header.

mode without-proxy-cache: browser cache 0 and force revalidate

mode with-proxy-cache: browser cache 0, proxy cache forever but force
revalidate

Initialize self.

browser_max_age = 0
proxy_max_age = 31104000
vary = ('Accept-Encoding', 'X-User-Path', 'X-User-Token')
etags = (<function etag_backrefs at 0x7f4bfa035378>, <function etag_descendants at 0x7f4bfa035400>, <function etag_modified at 0x7f4bfa035488>, <function etag_userid at 0x7f4bfa035510>, <function etag_blocked at 0x7f4bfa035598>)
class HTTPCacheStrategyStrongAdapter(context, request)[source]

Bases: adhocracy_core.caching.HTTPCacheStrategyBaseAdapter

Strong strategy adapter to set http cache header.

mode without-proxy-cache: browser cache forever

mode with-proxy-cache: browser cache forever, proxy cache forever but force
revalidate

Initialize self.

browser_max_age = 31104000
proxy_max_age = 31104000
vary = ('Accept-Encoding', 'X-User-Path', 'X-User-Token')
etags = (<function etag_modified at 0x7f4bfa035488>, <function etag_userid at 0x7f4bfa035510>, <function etag_blocked at 0x7f4bfa035598>)
purge_caching_proxy_after_commit_hook(success: bool, registry: pyramid.registry.Registry, request: <InterfaceClass pyramid.interfaces.IRequest>)[source]

Send PURGE requests for all changed resources to Varnish.

includeme(config)[source]

Register cache strategies.