Skip to main content

Caching infrastructure for web apps

Project description

Introduction

Caching of web pages is a complicated process: there are many possible policies to choose from, and the right policy can depend on factors such as who is making the request, the URL is being retrieved and resource negotiation settings such as accepted languages and encodings,

Hardcoding caching logic in an application is not desirable, especially for reusable code. It is also not possible to allow an administrator to manually configure the caching headers for every resource in an application. This packages tries to address this problem by providing a cache ruleset framework: it allows implementors to specify a ruleset for every component. Administrators can then define a policy which dictates the correct caching behaviour for each ruleset.

Depending on your environment there are different options for turning the ruleset into HTTP caching headers. If you are using Plone you can use five.caching to integrate with CacheSetup. In a WSGI environment you could set the ruleset in environ or a response header and add a piece of middleware which acts on those hints.

Usage

You can register rulesets using either zcml or direct python. If you use zcml you can use the cache:ruleset directive:

<configure
    xmlns="http://namespaces.zope.org/zope"
    xmlns:browser="http://namespaces.zope.org/browser"
    xmlns:cache="http://namespaces.zope.org/cache"/>

  <cache:ruleset
      for=".frontpage.FrontpageView"
      ruleset="plone-content-types"
      />

  <browser:page
      for="..interfaces.IFrontpage"
      class=".frontpage.FrontpageView"
      name="frontpage_view"
      template="templates/frontpage_view.pt"
      permission="zope2.View" />
</configure>

This example sets up a browser view called frontpage_view and associates it with the plone-content-types ruleset.

If you prefer to use python directly you can do so:

from z3c.caching.registry import register
from frontpage import FrontpageView

register(FrontpageView, "plone-content-types")

You can register a ruleset for objects, their interfaces or a base class.

To find the ruleset for an object use the lookup method:

from z3c.caching.registry import lookup

lookup(FrontpageView)

Changelog

1.0b1 - October 15, 2008

  • Initial release [wichert]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

z3c.caching-1.0b1.zip (11.3 kB view details)

Uploaded Source

File details

Details for the file z3c.caching-1.0b1.zip.

File metadata

  • Download URL: z3c.caching-1.0b1.zip
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for z3c.caching-1.0b1.zip
Algorithm Hash digest
SHA256 740051c31a040bced37cb11519ee256bb54eb8de3fd1c3ff5200e55c820bd396
MD5 cc36a2b679be468ad82f80d50185d545
BLAKE2b-256 7596df000cfe249d05f9f158560265e8f8e589b52c56c64be570505cb0494db2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page