Skip to main content

WSGI middleware for caching responses to disk.

Project description

Date:
2010-01-05
Authors:

Nathan R. Yergler <nathan@yergler.net>

wsgi_cache is a piece of WSGI middleware that provides disk caching for WSGI applications. It is somewhat coarse and rather inflexible, sort of like your grandpa.

wsgi_cache is designed to cache requests to a WSGI site to disk in a cache directory on disk. The cache directory will have the same directory layout as the requests (ie, if /foo/bar is requested, the foo directory will be made in the cache and bar will be stored there). There is no cache expiration beyond deleting cached files from the disk. This is a feature.

Installation

wsgi_cache can be installed as a Python egg, using easy_install:

$ easy_install wsgi_cache

Configuration

Configuration of wsgi_cache will often be done using Paste Deploy. In this situation, it can be configured as a filter:

[app:main]
use = egg:my_wsgi_app#app
filter-with = cache

[filter:cache]
use = egg:wsgi_cache#middleware
cache_dir = ./cache

The cache_dir is the only required configuration parameter, and will be interpreted as relative to global_conf['here'].

wsgi_cache also supports three additional configuration parameters:

  • content_type

    Specifies the content type used when serving cached resources; see Limitations below for details on this. By default this is set to text/html.

  • cache_paths

    A comma separated list of paths, starting with a /, that specifies the paths to cache. If specified, only requests to paths starting with one of these strings will be cached.

  • directory_index

    When accessing a path that ends in a / (like /monkeys/), wsgi_cache needs to create a special filename. By default this is __index.html. So by default, caching the page /monkeys/ saves to the file ${path_to_cache}/monkeys/__index.html; if we set directory_index to dir_x it would save to ${path_to_cache}/monkeys/dirx.

Behavior

When a request comes in, wsgi_cache examines the path to determine if it should be cached. Requests with a querystring are not cached, regardless of the use of cache_paths. If the request is supposed to be cached, wsgi_cache looks for the page in the cache and serves that copy, if available. If unavailable, the request is passed to the application and the result is saved and returned.

Note that in many situations, you’ll want to exploit wsgi_cache’s on disk cache layout to serve the cached version directly using your front end web server (ie, Apache with mod_rewrite).

Development

wsgi_cache may be developed using buildout

$ python bootstrap.py
$ ./bin/buildout

This will install any dependencies, as well as create a wrapper python script that can be used to run a shell with wsgi_cache on the Python path.

Running Tests

wsgi_cache uses nose for running tests. You can run the test suite by running:

$ python setup.py nosetests

If you’re using buildout for development, nose will be installed in the buildout for you:

$ ./bin/python setup.py nosetests

Limitations

  • wsgi_cache only stores the response body in order to allow serving of the cached files by a faster, static webserver. As such, it can only return a single content-type at this point.

Download

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

wsgi_cache-0.1.1.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wsgi_cache-0.1.1-py2.5.egg (6.0 kB view details)

Uploaded Egg

File details

Details for the file wsgi_cache-0.1.1.tar.gz.

File metadata

  • Download URL: wsgi_cache-0.1.1.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for wsgi_cache-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5719e2189a05cc8a245b2061af963d5d31a123e5c339050703d45d1fee45386e
MD5 a0d7f5cb5b6c0513d12e3ba83ad780ea
BLAKE2b-256 3bef4af1f8cdb319a2e3906e6a75beb17940146f09d0502df4db99aec73c1249

See more details on using hashes here.

File details

Details for the file wsgi_cache-0.1.1-py2.5.egg.

File metadata

File hashes

Hashes for wsgi_cache-0.1.1-py2.5.egg
Algorithm Hash digest
SHA256 56351b7d2856ea1e48379c78a896e35991c4c90666be4f45d3e4048485c754bc
MD5 5ff8fe4ad5e02f94ee6339ba6bdba4e9
BLAKE2b-256 c44270e8b0be63d2d6e7ae342f3b4ccc35c9882defee58f51f674d054b11525d

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