MemcachedBytecodeCache Class

Inheritance diagram of MemcachedBytecodeCache

class MemcachedBytecodeCache(client, prefix='jinja2/bytecode/', timeout=None)

This class implements a bytecode cache that uses a memcache cache for storing the information. It does not enforce a specific memcache library (tummy’s memcache or cmemcache) but will accept any class that provides the minimal interface required.

Libraries compatible with this class:

(Unfortunately the django cache interface is not compatible because it does not support storing binary data, only unicode. You can however pass the underlying cache client to the bytecode cache which is available as django.core.cache.cache._client.)

The minimal interface for the client passed to the constructor is this:

class MinimalClientInterface
set(key, value[, timeout])

Stores the bytecode in the cache. value is a string and timeout the timeout of the key. If timeout is not provided a default timeout or no timeout should be assumed, if it’s provided it’s an integer with the number of seconds the cache item should exist.

get(key)

Returns the value for the cache key. If the item does not exist in the cache the return value must be None.

The other arguments to the constructor are the prefix for all keys that is added before the actual cache key and the timeout for the bytecode in the cache system. We recommend a high (or no) timeout.

This bytecode cache does not support clearing of used items in the cache. The clear method is a no-operation function.

Methods

__init__(client[, prefix, timeout])
clear() Clears the cache.
dump_bytecode(bucket)
get_bucket(environment, name, filename, source) Return a cache bucket for the given template.
get_cache_key(name[, filename]) Returns the unique hash key for this template name.
get_source_checksum(source) Returns a checksum for the source.
load_bytecode(bucket)
set_bucket(bucket) Put the bucket into the cache.

Descriptions

class MemcachedBytecodeCache

Method details

__init__(client, prefix='jinja2/bytecode/', timeout=None)
dump_bytecode(bucket)
load_bytecode(bucket)

Inherited member details

clear()

Clears the cache. This method is not used by Jinja2 but should be implemented to allow applications to clear the bytecode cache used by a particular environment.

get_bucket(environment, name, filename, source)

Return a cache bucket for the given template. All arguments are mandatory but filename may be None.

get_cache_key(name, filename=None)

Returns the unique hash key for this template name.

get_source_checksum(source)

Returns a checksum for the source.

set_bucket(bucket)

Put the bucket into the cache.

Table Of Contents

Previous topic

FileSystemBytecodeCache Class

Next topic

BytesIO