Skip to main content

PageCache

WSGI caching middleware.

PageCache is a WSGI middleware that can be used to cache complete responses from WSGI applications. PageCache works well with memcached but can be used with other caching backends as well.

PageCache has not been widely tested, use with caution.

Usage

Here’s a simple example to get you started:

from pagecache import PageCacheMiddleware

app = ...
cache = memcache.Client(...)
cached_urls = (('/foo', 30, 120), # url prefix, TTL, grace period
               ('/bar', 3600, 60))
app = PageCacheMiddleware(app, cached_urls, cache)

Cached urls

The list of urls to cache is given in the cached_urls list (or tuple). Each entry of this list is a tuple in the following format: (<url prefix>, <TTL in seconds>, <grace period in seconds>)

Pages are served from the cache in the TTL period. When the TTL period has expired the grace period begins. The first request coming in in the grace period will recalculate the page and store the new result in the cache. While the new result is being calculated stale results are served from the cache (until the grace period expires). This is to protect against the dog-pile effect

The cache object

PageCache was only tested with memcached, but it may work with other cache backends as well. The only requirement is that the cache object should have the following methods with reasonably similar semantics as in memcached: get, set, delete, add

A note on cookies

All Set-Cookie headers returned by the application will be ignored. Also, depending on your application you’ll most probably want to make sure that the application doesn’t use any incoming cookie information to calculate responses that will be cached.

Install

You can install the latest version from the github repository:

git clone git://github.com/abiczo/pagecache.git
cd pagecache
python setup.py install

TODO

  • more unit testing

  • better syntax for the cached urls configuration

  • regexp based url matching

  • configurable cache keys (so that multiple applications can use the same memcached instance without having to worry about having the same cached urls)

  • configurable request charset

Patches / pull-requests are welcome.

Contact

abiczo@gmail.com

Metadata

Release files for pagecache 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pagecache 0.1.1
File Size Uploaded Provenance Actions
pagecache-0.1.1.tar.gz 4.4 kB Without provenance Details for pagecache-0.1.1.tar.gz

Release files / pagecache-0.1.1.tar.gz

Download URL pagecache-0.1.1.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
63bd2dd422a97b7b5da8efb2b1ce510d1024c9d765fd206a87bb342c405d54bd
BLAKE2b-256 checksum
How to use checksums
7c3ab9cc7cb0460d674af01d0ae13beb884c20e97011039ac423ec4ec779d316
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for pagecache 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page