Skip to main content

Django cache backend using pylibmc

Project description

This package provides a memcached cache backend for Django using pylibmc. You want to use pylibmc because it’s fast.

Requirements

django-pylibmc requires Django 1.3+. It was written and tested on Python 2.7.

Installation

Get it from pypi:

pip install django-pylibmc

or github:

pip install -e git://github.com/jbalogh/django-pylibmc.git#egg=django-pylibmc

Usage

Your cache backend should look something like this:

CACHES = {
    'default': {
        'BACKEND': 'django_pylibmc.memcached.PyLibMCCache',
        'LOCATION': 'localhost:11211',
        'TIMEOUT': 500,
        'BINARY': True,
        'OPTIONS': {  # Maps to pylibmc "behaviors"
            'tcp_nodelay': True,
            'ketama': True
        }
    }
}

If you want to use the memcached binary protocol, set the BINARY key’s value to True as shown above. BINARY is False by default.

If you want to control pylibmc behaviors, use the OPTIONS. OPTIONS is an empty dict by default.

Pylibmc supports compression and the minimum size (in bytes) of values to compress can be set via the Django setting PYLIBMC_MIN_COMPRESS_LEN. The default is 0, which is disabled.

Configuration with Environment Variables

Optionally, the memcached connection can be configured with environment variables (on platforms like Heroku). To do so, declare the following variables:

  • MEMCACHE_SERVERS

  • MEMCACHE_USERNAME

  • MEMCACHE_PASSWORD

Caveats

This package breaks away from the current handling of timeout=0 in Django. Django converts 0 into the default timeout, while django-pylibmc leaves it as 0. memcached takes 0 to mean “infinite timeout.” You can still pass None to get the default timeout.

Testing

Run the tests like this:

python tests/test.py

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

django-pylibmc-0.5.0.tar.gz (4.7 kB view details)

Uploaded Source

File details

Details for the file django-pylibmc-0.5.0.tar.gz.

File metadata

File hashes

Hashes for django-pylibmc-0.5.0.tar.gz
Algorithm Hash digest
SHA256 a78f2975b7b5cb61cc15f7241da514b282fda4543c6346602a2fc275499df1f2
MD5 df603f3314909117b0bc36fe360a7e3d
BLAKE2b-256 6d736887e5b3be4fae35ce6c30d2ca8fa9e939d273a952ce13dd1054ab755d20

See more details on using hashes here.

Supported by

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