Caching

Helpers for dealing with HTTP level caching.

The Cache-Control and Expires header can be defined while adding a handler to the environment:

class MyService(Service):

    def run(self):
        self.environment.add_handler(...,
                                     cache=CacheConfig(
                                        timedelta(minutes=10),
                                        expires=timedelta(minutes=10))

The details of setting the CacheControl header are documented in the CacheConfig(). The expires argument simply takes a datetime.timedelta() as input and will then generate the Expires header based on the current time and the datetime.timedelta().

supercell.cache.CacheConfig(max_age, s_max_age=None, public=False, private=False, no_cache=False, no_store=False, must_revalidate=True, proxy_revalidate=False)

Create a CacheConfigT with default values. :param max_age: Number of seconds the response can be cached :type max_age: datetime.timedelta

Parameters:
  • s_max_age (datetime.timedelta) – Like max_age but only applies to shared caches
  • public (bool) – Marks responses as cachable even if they contain authentication information
  • private (bool) – Allows the browser to cache the result but not shared caches
  • no_cache (bool) – If True caches will revalidate the request before delivering the cached copy
  • no_store (bool) – Caches should not store any cached copy.
  • must_revalidate (bool) – Tells the cache to not serve stale copies of the response
  • proxy_revalidate (bool) – Like must_revalidate except it only applies to public caches
Read the Docs v: latest
Versions
latest
v0.4.0
v0.3.0
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.