Package amplee :: Package storage :: Module storememcache :: Class StorageMemcache
[hide private]
[frames] | no frames]

Class StorageMemcache

source code

object --+    
         |    
   Storage --+
             |
            StorageMemcache

Instance Methods [hide private]
 
__init__(self, servers, key_generator=None, storage=None, encoding='utf-8')
The Memcache storage allows to use memcache as the master storage but can also be used as a proxy to another storage providing therefore a transparent and powerful cache mechanism to an application.
source code
 
_key_maker(self, *args)
Default key generator
source code
 
_update_set(self, set_key, member_key, remove=False) source code
 
_create_set_keys(self, collection_name) source code
 
shutdown(self)
Shutdowns the memcache connection.
source code
object
create_container(self, collection_name)
Calls the proxied storage create_container method to perform the operation.
source code
StorageResourceInfo or subclass
info(self, collection_name, resource_name=None, **kwargs)
Returns a StorageResourceInfo of which the key attribute is a StorageMemcacheResourceInfo instance.
source code
object
get_content(self, info)
Returns the content as a string of the resource found at 'info.key'.
source code
string
get_meta_data(self, info)
Returns the content as a string of the resource found at 'info.key'.
source code
 
put_content(self, info, content, **kwargs)
Set the content at 'info.key' of the resource.
source code
 
put_meta_data(self, info, content, **kwargs)
Set the content at 'info.key' of the resource.
source code
 
remove_content(self, info)
Remove the resource at 'info.key' from the cache and if provided from the proxied storage.
source code
 
remove_meta_data(self, info)
Remove the resource at 'info.key' from the cache and if provided from the proxied storage.
source code
 
persist(self, path_list, *args, **kwargs)
Does nothing in this storage but calls the persist method of the proxied storage.
source code
bool
exists(self, info)
Returns True if the resource at 'info.key' exists in either the cache or alternatively the proxied storage.
source code
dict
ls(self, collection_name, ext=None)
Calls the ls() method of the proxied storage and returns a dictionnary of StorageResourceInfo instances.
source code
tuple
ils(self, collection_name, ext=None)
Calls the ils() method of the proxied storage and yields tuples of StorageResourceInfo instances.
source code

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

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, servers, key_generator=None, storage=None, encoding='utf-8')
(Constructor)

source code 

The Memcache storage allows to use memcache as the master storage but can also be used as a proxy to another storage providing therefore a transparent and powerful cache mechanism to an application.

By default it will look for the cmemcache module and if not available will fallback to the regular memcache module.

The ``servers`` argument is a list of strings supporting the common format to connect to a memcached server.

The ``key_generator`` is a callable that takes the arguments provided to the info() method and returns a new string used as the key within the memcached instance. It should therefore be unique. If not provided it will compute the sha (sha256 if available) hashing of the arguments provided to the info() method prefixed by the name of the collection.

The ``storage``, if provided, must be an instance of another storage. Each operation on the memcache storage will then propagated to the inner cache transparently.

Note that because the cmemcache module is not entirely thread safe, this storage uses a lock to synchronize the different write operations. Hopefully this should not decrease the capacity of this storage.

Note also that this storage should not really be used as a standalone as its behavior varies slightly from the other storages. You should always use this as a proxy storage.
Overrides: object.__init__

shutdown(self)

source code 
Shutdowns the memcache connection.
Overrides: Storage.shutdown

create_container(self, collection_name)

source code 
Calls the proxied storage create_container method to perform the operation.
Returns: object
the subclass may or may not return an object upon the creation of the container
Overrides: Storage.create_container

info(self, collection_name, resource_name=None, **kwargs)

source code 
Returns a StorageResourceInfo of which the key attribute is a StorageMemcacheResourceInfo instance.
Returns: StorageResourceInfo or subclass
an object representing the resource within the storage
Overrides: Storage.info

get_content(self, info)

source code 

Returns the content as a string of the resource found at 'info.key'.

Keyword arguments info -- as returned by info()
Returns: object
content of the resource
Overrides: Storage.get_content

get_meta_data(self, info)

source code 

Returns the content as a string of the resource found at 'info.key'. If no resource could be found, an IOError is raised.

Keyword arguments info -- as returned by info()
Returns: string
content of the atom entry
Overrides: Storage.get_meta_data

put_content(self, info, content, **kwargs)

source code 

Set the content at 'info.key' of the resource.

Keyword arguments info -- as returned by info()

content -- data as a string object or a file object. In the latter case read() MUST return the full content as a byte string.
Overrides: Storage.put_content

put_meta_data(self, info, content, **kwargs)

source code 

Set the content at 'info.key' of the resource.

Keyword arguments info -- as returned by info()

content -- data as a string or a file object. In the latter case read() MUST return the full content as a byte string.
Overrides: Storage.put_meta_data

remove_content(self, info)

source code 

Remove the resource at 'info.key' from the cache and if provided from the proxied storage.

Keyword arguments info -- as returned by info()
Overrides: Storage.remove_content

remove_meta_data(self, info)

source code 

Remove the resource at 'info.key' from the cache and if provided from the proxied storage.

Keyword arguments info -- as returned by info()
Overrides: Storage.remove_meta_data

persist(self, path_list, *args, **kwargs)

source code 
Does nothing in this storage but calls the persist method of the proxied storage.
Overrides: Storage.persist

exists(self, info)

source code 

Returns True if the resource at 'info.key' exists in either the cache or alternatively the proxied storage.

Returns False otherwise.

Note that because it first looks at the cache, the resource may not be present in the proxied storage and still return True creating some kind of false positive.

Keyword arguments info -- as returned by info()
Returns: bool
True if the test succeeds, False otherwise.
Overrides: Storage.exists

ls(self, collection_name, ext=None)

source code 
Calls the ls() method of the proxied storage and returns a dictionnary of StorageResourceInfo instances. The key attribute is an instance of StorageMemcacheResourceInfo which points in turn to the proxied info value of the proxied storage.
Returns: dict
a dictionnary of existing members, their identifier and a StorageResourceInfo instance representing the resource.
Overrides: Storage.ls

ils(self, collection_name, ext=None)

source code 
Calls the ils() method of the proxied storage and yields tuples of StorageResourceInfo instances. The key attribute is an instance of StorageMemcacheResourceInfo which points in turn to the proxied info value of the proxied storage.
Returns: tuple
existing members, their identifier and a StorageResourceInfo instance representing the resource.
Overrides: Storage.ils