Package wtf :: Package app :: Package services :: Module memcache :: Class TransparentCacheDecorator
[hide private]
[frames] | no frames]

Class TransparentCacheDecorator

source code

        object --+    
                 |    
util.BaseDecorator --+
                     |
                    TransparentCacheDecorator

Decorator which transparently memoizes a function call
Instance Methods [hide private]
 
__init__(self, func, keygen, mcc, max_age, nocache=False, disabled=False, pass_=False, local=False, nolocal=False, recache=False)
Initialization
source code
any
__call__(self, *args, **kwargs)
Compute the key, check for presence and return the cached result
source code

Inherited from util.BaseDecorator: __get__, __getattr__

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Static Methods [hide private]
a new object with type S, a subtype of T

__new__(cls, func, keygen, mcc, max_age, nocache=False, disabled=False, pass_=False, local=False, nolocal=False, recache=False)
Construction
source code
Instance Variables [hide private]

Inherited from util.BaseDecorator: __doc__, __name__

Inherited from util.BaseDecorator (private): _func

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__new__(cls, func, keygen, mcc, max_age, nocache=False, disabled=False, pass_=False, local=False, nolocal=False, recache=False)
Static Method

source code 
Construction
Returns:
a new object with type S, a subtype of T

Overrides: object.__new__

__init__(self, func, keygen, mcc, max_age, nocache=False, disabled=False, pass_=False, local=False, nolocal=False, recache=False)
(Constructor)

source code 
Initialization
Parameters:
  • func (callable) - The function to decorate
  • keygen (callable) - Key generator callable
  • mcc (Memcache) - Memcache connector
  • nocache (int) - Evaluate nocache argument?
  • disabled (bool) - Is this decorator disabled?
  • pass_ (bool) - Pass memcache to the function?
  • local (bool or float) - Cache locally as well? (It will be deepcopied for usage) The local cachetime will be local * max_age of the memcache age. (if False, it's 0, if True, it's 1)
  • nolocal (int) - Evaluate nolocal argument?
  • recache (bool) - Evaluate recache argument? Useful for backfilling. The memcache won't be asked, but set unconditionally.
Overrides: object.__init__

__call__(self, *args, **kwargs)
(Call operator)

source code 

Compute the key, check for presence and return the cached result

If the key is not cached yet, just call the function and store the result in the cache. Except nocache is requested by the caller and activated in this decorator instance.

Parameters:
  • args (tuple) - Function's positional arguments
  • kwargs (dict) - Function's keyword arguments
Returns: any
Whatever the decorated function returns
Raises:
  • Exception - Whatever the decorated function raises
Overrides: util.BaseDecorator.__call__