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

Class GlobalMemcache

source code

object --+
         |
        GlobalMemcache

Actual global memcache service object
Instance Methods [hide private]
 
__init__(self, pools, max_age, grace_time, retry_time, compress_threshold, padded, split, prefix, largest_slab)
Initialization
source code
list
status(self)
Determine pool status
source code
 
shutdown(self)
Shutdown the memcache pools
source code
Memcache
connect(self, max_age=None, prepare=None, exceptions=None)
Create a memcache connector
source code
TransparentCacheDecorator
memcached(self, keygen, **kwargs)
Cache the function transparently
source code
callable
connection(self, *args, **kwargs)
Inject a new connector into function's arguments
source code
str
_prepare(self, key)
Default key preparator
source code

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

Instance Variables [hide private]
callable _create
Memcache wrapper creator
int _max_age
Globally configured max age
MemcacheWrapper or Memcache _mc
Default memcache wrapper
tuple _pools
Pool list
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, pools, max_age, grace_time, retry_time, compress_threshold, padded, split, prefix, largest_slab)
(Constructor)

source code 
Initialization
Parameters:
  • pools (iterable) - Pool list
  • max_age (int) - Default expire time (None for no such default)
  • grace_time (int) - Grace time, see ext.memcache.Memcache.__init__ for details
  • retry_time (int) - Retry time, see ext.memcache.Memcache.__init__ for details
  • compress_threshold (int) - Compression threshold
  • padded (bool) - Padded, yes/no? (None for the default)
  • split (bool) - Split yes/no? (None for the default)
  • prefix (str) - global key prefix
  • largest_slab (int) - Largest slab size (None for the default)
Overrides: object.__init__

status(self)

source code 

Determine pool status

Each status is a dict {'spec': 'spec', 'alive': bool, 'weight': int}.

Returns: list
The status of the pools ([status, ...])

shutdown(self)

source code 

Shutdown the memcache pools

The pools are no longer usable after that. This is for final application shutdown. Don't use it in the application itself!

connect(self, max_age=None, prepare=None, exceptions=None)

source code 

Create a memcache connector

Although the method name suggests it, the method doesn't actually connect. The connection is selected by key later when using the connector to actually do something.

Parameters:
  • max_age (int) - Default max age for store commands in seconds (overriding the configured default)
  • prepare (callable) - Key preparation function (overriding the default)
  • exceptions (bool) - Pass exceptions to the caller? (Default: False)
Returns: Memcache
The memcache connector (may be wrapped for requested functionality, so it's not necessarily a real Memcache)

memcached(self, keygen, **kwargs)

source code 

Cache the function transparently

Recognized keyword parameters:

max_age
[int] Default expire time for storing operations
prepare
[callable] Key preparation function
nocache
[int] Nocache behavior. See services.memcache for details.
recache
[bool] Recache behavioue. See services.memcache for details.
disabled
[bool] Disable this memcache decorator (useful for debugging)?
pass_
[bool] If true, the memcache connector will be passed to the function
exceptions
[bool] Memcache exception behavior (pass through = True)
Parameters:
  • keygen (callable) - Key generator function
  • kwargs (dict) - Keyword arguments
Returns: TransparentCacheDecorator
The memcached decorator

connection(self, *args, **kwargs)

source code 

Inject a new connector into function's arguments

The method takes either one positional argument (the function to decorate) or keyword arguments which override default options:

max_age
[int] Default expire time for storing operations
prepare
[callable] Key preparation function
nocache
[int] Nocache behavior. See services.memcache for details.
disabled
[bool] Disable the memcache connection (useful for debugging)
exceptions
[bool] Memcache exception behaviour (pass through = True)
Parameters:
  • args (tuple) - Positional arguments
  • kwargs (tuple) - keyword arguments
Returns: callable
Decorator or decorator factory
Raises:
  • TypeError - The arguments are formally invalid

_prepare(self, key)

source code 

Default key preparator

The input key is assumed to be a string and is just MD5 hashed. The hexdigest is the resulting key then.

Parameters:
  • key (str) - The key to prepare
Returns: str
The prepared key