Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes
MoinMoin.support.werkzeug.contrib.cache.GAEMemcachedCache Class Reference
Inheritance diagram for MoinMoin.support.werkzeug.contrib.cache.GAEMemcachedCache:
Inheritance graph
[legend]
Collaboration diagram for MoinMoin.support.werkzeug.contrib.cache.GAEMemcachedCache:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def get
def get_dict
def add
def set
def get_many
def set_many
def delete
def delete_many
def clear
def inc
def dec

Public Attributes

 key_prefix
 default_timeout

Detailed Description

Connects to the Google appengine memcached Cache.

:param default_timeout: the default timeout that is used if no timeout is
                        specified on :meth:`~BaseCache.set`.
:param key_prefix: a prefix that is added before all keys.  This makes it
                   possible to use the same memcached server for different
                   applications.  Keep in mind that
                   :meth:`~BaseCache.clear` will also clear keys with a
                   different prefix.

Definition at line 414 of file cache.py.


Constructor & Destructor Documentation

def MoinMoin.support.werkzeug.contrib.cache.GAEMemcachedCache.__init__ (   self,
  default_timeout = 300,
  key_prefix = None 
)

Definition at line 426 of file cache.py.

00426 
00427     def __init__(self, default_timeout=300, key_prefix=None):
00428         from google.appengine.api import memcache
00429         MemcachedCache.__init__(self, memcache.Client(),
00430                                 default_timeout, key_prefix)
00431 


Member Function Documentation

def MoinMoin.support.werkzeug.contrib.cache.MemcachedCache.add (   self,
  key,
  value,
  timeout = None 
) [inherited]
Works like :meth:`set` but does not override already existing
values.

:param key: the key to set
:param value: the value for the key
:param timeout: the cache timeout for the key or the default
        timeout if not specified.

Reimplemented from MoinMoin.support.werkzeug.contrib.cache.BaseCache.

Definition at line 343 of file cache.py.

00343 
00344     def add(self, key, value, timeout=None):
00345         if timeout is None:
00346             timeout = self.default_timeout
00347         if isinstance(key, unicode):
00348             key = key.encode('utf-8')
00349         if self.key_prefix:
00350             key = self.key_prefix + key
00351         self._client.add(key, value, timeout)

Here is the caller graph for this function:

Clears the cache.  Keep in mind that not all caches support
clearning of the full cache.

Reimplemented from MoinMoin.support.werkzeug.contrib.cache.BaseCache.

Definition at line 396 of file cache.py.

00396 
00397     def clear(self):
00398         self._client.flush_all()

def MoinMoin.support.werkzeug.contrib.cache.MemcachedCache.dec (   self,
  key,
  delta = 1 
) [inherited]
Decrements the value of a key by `delta`.  If the key does
not yet exist it is initialized with `-delta`.

For supporting caches this is an atomic operation.

:param key: the key to increment.
:param delta: the delta to subtract.

Reimplemented from MoinMoin.support.werkzeug.contrib.cache.BaseCache.

Definition at line 406 of file cache.py.

00406 
00407     def dec(self, key, delta=1):
00408         if isinstance(key, unicode):
00409             key = key.encode('utf-8')
00410         if self.key_prefix:
00411             key = self.key_prefix + key
00412         self._client.decr(key, delta)
00413 

Deletes `key` from the cache.  If it does not exist in the cache
nothing happens.

:param key: the key to delete.

Reimplemented from MoinMoin.support.werkzeug.contrib.cache.BaseCache.

Definition at line 377 of file cache.py.

00377 
00378     def delete(self, key):
00379         if isinstance(key, unicode):
00380             key = key.encode('utf-8')
00381         if self.key_prefix:
00382             key = self.key_prefix + key
00383         if _test_memcached_key(key):
00384             self._client.delete(key)

Deletes multiple keys at once.

:param keys: The function accepts multiple keys as positional
     arguments.

Reimplemented from MoinMoin.support.werkzeug.contrib.cache.BaseCache.

Definition at line 385 of file cache.py.

00385 
00386     def delete_many(self, *keys):
00387         new_keys = []
00388         for key in keys:
00389             if isinstance(key, unicode):
00390                 key = key.encode('utf-8')
00391             if self.key_prefix:
00392                 key = self.key_prefix + key
00393             if _test_memcached_key(key):
00394                 new_keys.append(key)
00395         self._client.delete_multi(new_keys)

def MoinMoin.support.werkzeug.contrib.cache.MemcachedCache.get (   self,
  key 
) [inherited]
Looks up key in the cache and returns it.  If the key does not
exist `None` is returned instead.

:param key: the key to be looked up.

Reimplemented from MoinMoin.support.werkzeug.contrib.cache.BaseCache.

Definition at line 305 of file cache.py.

00305 
00306     def get(self, key):
00307         if isinstance(key, unicode):
00308             key = key.encode('utf-8')
00309         if self.key_prefix:
00310             key = self.key_prefix + key
00311         # memcached doesn't support keys longer than that.  Because often
00312         # checks for so long keys can occour because it's tested from user
00313         # submitted data etc we fail silently for getting.
00314         if _test_memcached_key(key):
00315             return self._client.get(key)

Here is the caller graph for this function:

Works like :meth:`get_many` but returns a dict::

    d = cache.get_dict("foo", "bar")
    foo = d["foo"]
    bar = d["bar"]

:param keys: The function accepts multiple keys as positional
     arguments.

Reimplemented from MoinMoin.support.werkzeug.contrib.cache.BaseCache.

Definition at line 316 of file cache.py.

00316 
00317     def get_dict(self, *keys):
00318         key_mapping = {}
00319         have_encoded_keys = False
00320         for idx, key in enumerate(keys):
00321             if isinstance(key, unicode):
00322                 encoded_key = key.encode('utf-8')
00323                 have_encoded_keys = True
00324             else:
00325                 encoded_key = key
00326             if self.key_prefix:
00327                 encoded_key = self.key_prefix + encoded_key
00328             if _test_memcached_key(key):
00329                 key_mapping[encoded_key] = key
00330         # the keys call here is important because otherwise cmemcache
00331         # does ugly things.  What exaclty I don't know, i think it does
00332         # Py_DECREF but quite frankly i don't care.
00333         d = rv = self._client.get_multi(key_mapping.keys())
00334         if have_encoded_keys or self.key_prefix:
00335             rv = {}
00336             for key, value in d.iteritems():
00337                 rv[key_mapping[key]] = value
00338         if len(rv) < len(keys):
00339             for key in keys:
00340                 if key not in rv:
00341                     rv[key] = None
00342         return rv

Returns a list of keys.  For each key a item in the list is
created.  Example::

    foo, bar = cache.get_many("foo", "bar")

If a key can't be looked up `None` is returned for that key
instead.

:param keys: The function accepts multiple keys as positional
     arguments.

Reimplemented from MoinMoin.support.werkzeug.contrib.cache.BaseCache.

Definition at line 361 of file cache.py.

00361 
00362     def get_many(self, *keys):
00363         d = self.get_dict(*keys)
00364         return [d[key] for key in keys]

Here is the call graph for this function:

def MoinMoin.support.werkzeug.contrib.cache.MemcachedCache.inc (   self,
  key,
  delta = 1 
) [inherited]
Increments the value of a key by `delta`.  If the key does
not yet exist it is initialized with `delta`.

For supporting caches this is an atomic operation.

:param key: the key to increment.
:param delta: the delta to add.

Reimplemented from MoinMoin.support.werkzeug.contrib.cache.BaseCache.

Definition at line 399 of file cache.py.

00399 
00400     def inc(self, key, delta=1):
00401         if isinstance(key, unicode):
00402             key = key.encode('utf-8')
00403         if self.key_prefix:
00404             key = self.key_prefix + key
00405         self._client.incr(key, delta)

def MoinMoin.support.werkzeug.contrib.cache.MemcachedCache.set (   self,
  key,
  value,
  timeout = None 
) [inherited]
Adds or overrides a key in the cache.

:param key: the key to set
:param value: the value for the key
:param timeout: the cache timeout for the key or the default
        timeout if not specified.

Reimplemented from MoinMoin.support.werkzeug.contrib.cache.BaseCache.

Definition at line 352 of file cache.py.

00352 
00353     def set(self, key, value, timeout=None):
00354         if timeout is None:
00355             timeout = self.default_timeout
00356         if isinstance(key, unicode):
00357             key = key.encode('utf-8')
00358         if self.key_prefix:
00359             key = self.key_prefix + key
00360         self._client.set(key, value, timeout)

Here is the caller graph for this function:

def MoinMoin.support.werkzeug.contrib.cache.MemcachedCache.set_many (   self,
  mapping,
  timeout = None 
) [inherited]
Sets multiple keys and values from a dict.

:param mapping: a dict with the values to set.
:param timeout: the cache timeout for the key or the default
        timeout if not specified.

Reimplemented from MoinMoin.support.werkzeug.contrib.cache.BaseCache.

Definition at line 365 of file cache.py.

00365 
00366     def set_many(self, mapping, timeout=None):
00367         if timeout is None:
00368             timeout = self.default_timeout
00369         new_mapping = {}
00370         for key, value in mapping.iteritems():
00371             if isinstance(key, unicode):
00372                 key = key.encode('utf-8')
00373             if self.key_prefix:
00374                 key = self.key_prefix + key
00375             new_mapping[key] = value
00376         self._client.set_multi(new_mapping, timeout)


Member Data Documentation

Definition at line 79 of file cache.py.

Definition at line 303 of file cache.py.


The documentation for this class was generated from the following file: