txcaching package

Submodules

txcaching.cache module

txcaching.cache.ConfigSchema

alias of Config

class txcaching.cache.RequestCachingWrapper(request, cache_key, cache_proto, func, resource, expireTime=0, exclude_self=False, class_name='')[source]

Bases: object

Request wrapper for asynchronous functions render_GET (returning server.NOT_DONE_YET). This class is not to be used directly.

finish()[source]
getSession()[source]
notifyFinish()[source]
setResponseCode(code, error)[source]
write(data)[source]
txcaching.cache.add(key, val, flags=0, expireTime=0)[source]

Wrapper for twisted.protocol.memcached.MemCacheProtocol.add()

txcaching.cache.append(key, val)[source]

Wrapper for twisted.protocol.memcached.MemCacheProtocol.append()

txcaching.cache.cache(cache_key=None, lazy_key=<function default_lazy_key at 0x2fcf050>, class_name='', expireTime=0, exclude_self=False)[source]

Cache the output of the function. Shall be used as decorator.

Parameters:
  • cache_key – Set up the cache key directly. In this case, only one key will be used to store function output, regardless from its arguments. Usually it is not recommended to use.
  • lazy_key – Function that uses the function and its arguments to produce the cache keys. For most cases, default_lazy_key() will be fine, but you may use your own function.
  • class_name – Name of class of the resource. It is required because the decorator can only see an unbound method, unrelated to any class.
  • expireTime – The lifetime of the cache key. If set to 0, lifetime is not limited.
  • exclude_self – If it is true, the state of resource object will not be used to create cache key. If it is set to false, changing the resource object will change the cache key, even if the other function arguments are the same.
txcaching.cache.cache_async_render_GET(expireTime=0, redundant_args=(), exclude_self=False, class_name='')[source]

Cache the output of function render_GET which returns server.NOT_DONE_YET. If it returns a string, use cache_sync_render_GET() instead. Shall be used as decorator.

Parameters:
  • expireTime – The lifetime of the cache key. If set to 0, lifetime is not limited.
  • redundant_args – Request arguments we want to ignore. For example, ExtJS generates the random argument _dc to prevent browser caching. We can get rid of it using redundant_args=(“_dc”,)
  • exclude_self – If it is true, the state of resource object will not be used to create cache key. If it is set to false, changing the resource object will change the cache key, even if the request parameters are the same.
  • class_name – Name of class of the resource. It is required because the decorator can only see an unbound method, unrelated to any class.
txcaching.cache.cache_sync_render_GET(expireTime=0, redundant_args=(), exclude_self=False, class_name='')[source]

Cache the output of function render_GET which returns a string. If it returns server.NOT_DONE_YET, use cache_async_render_GET() instead. Shall be used as decorator.

Parameters:
  • expireTime – The lifetime of the cache key. If set to 0, lifetime is not limited.
  • redundant_args – Request arguments we want to ignore. For example, ExtJS generates the random argument _dc to prevent browser caching. We can get rid of it using redundant_args=(“_dc”,)
  • exclude_self – If it is true, the state of resource object will not be used to create cache key. If it is set to false, changing the resource object will change the cache key, even if the request parameters are the same.
  • class_name – Name of class of the resource. It is required because the decorator can only see an unbound method, unrelated to any class.
txcaching.cache.connect()[source]

Connect to memcached server

Returns:Deferred which fires with protocol instance
txcaching.cache.decrement(key, val=1)[source]

Wrapper for twisted.protocol.memcached.MemCacheProtocol.decrement()

txcaching.cache.default_lazy_key(func, args, kwargs, exclude_self=False, class_name='')[source]

Default function which generates cache key using function and its arguments. All the arguments must be picklable.

Parameters:
  • func – Function to cache
  • args – Function arguments
  • kwargs – Function keyword arguments
  • exclude_self – If the function is a method and this parameter is set to true, the state of object will not be used to create cache key.
  • class_name – If the function is a method, name of class of the object must be set up.
Returns:

key for caching server (str)

txcaching.cache.delete(key)[source]

Wrapper for twisted.protocol.memcached.MemCacheProtocol.delete()

txcaching.cache.flushAll()[source]

Wrapper for twisted.protocol.memcached.MemCacheProtocol.flushAll()

txcaching.cache.get(key, withIdentifier=False)[source]

Wrapper for twisted.protocol.memcached.MemCacheProtocol.get()

txcaching.cache.getMultiple(keys, withIdentifier=False)[source]

Wrapper for twisted.protocol.memcached.MemCacheProtocol.getMultiple()

txcaching.cache.increment(key, val=1)[source]

Wrapper for twisted.protocol.memcached.MemCacheProtocol.increment()

txcaching.cache.load_config(**kwargs)[source]

Load configuration. Must be called before use of other method of this module. By default, caching is disabled.

txcaching.cache.prepend(key, val)[source]

Wrapper for twisted.protocol.memcached.MemCacheProtocol.prepend()

txcaching.cache.replace(key, val, flags=0, expireTime=0)[source]

Wrapper for twisted.protocol.memcached.MemCacheProtocol.replace()

txcaching.cache.set(key, val, flags=0, expireTime=0)[source]

Wrapper for twisted.protocol.memcached.MemCacheProtocol.set()

txcaching.cache.stats()[source]

Wrapper for twisted.protocol.memcached.MemCacheProtocol.stats()

txcaching.cache.version()[source]

Wrapper for twisted.protocol.memcached.MemCacheProtocol.version()

txcaching.keyregistry module

txcaching.keyregistry.all()[source]

Get copy of the registry. For debug only.

txcaching.keyregistry.clear()[source]

Clear the registry

txcaching.keyregistry.func_id(func, class_name='')[source]

Function unique identifier.

txcaching.keyregistry.key(func, args=(), kwargs={})[source]

Key which has been added by the function with particular arguments.

txcaching.keyregistry.keys(func)[source]

All the keys which have been added by the function

txcaching.keyregistry.register(key, func, args=(), kwargs={}, class_name='')[source]

Add function call to the registry

Parameters:
  • key (str) – cache key
  • func – function to cache
  • args (tuple) – function arguments
  • kwargs (dict) – function keyword arguments
  • class_name – If the function is a method, name of class of the object must be set up.
txcaching.keyregistry.remove(func)[source]

Remove function from registry with all the keys associated with it.

Module contents

Table Of Contents

Previous topic

Welcome to txcaching’s documentation!

This Page