Package bw :: Package poseidon :: Module memcache
[frames] | no frames]

Module memcache

client module for memcached (memory cache daemon)

Overview

See the MemCached homepage for more about memcached.

Usage summary

This should give you a feel for how this module operates:

   import memcache
   mc = memcache.Client(['127.0.0.1:11211'], debug=0)

   mc.set("some_key", "Some value")
   value = mc.get("some_key")

   mc.set("another_key", 3)
   mc.delete("another_key")

   mc.set("key", "1")   # note that the key used for incr/decr must be a string.
   mc.incr("key")
   mc.decr("key")

The standard way to use memcache with a database is like this:

   key = derive_key(obj)
   obj = mc.get(key)
   if not obj:
       obj = backend_api.get(...)
       mc.set(obj)

   # we now have obj, and future passes through this code
   # will use the object from the cache.

Detailed Documentation

More detailed documentation is available in the Client class.


Version: 1.37

Author: Evan Martin <martine@danga.com>

Copyright: Copyright (C) 2003 Danga Interactive

License: Python

Classes
  Client
Object representing a pool of memcache servers.
Functions
 
check_key(key, key_extra_len=0)
Checks sanity of key.
Variables
  SERVER_MAX_KEY_LENGTH = 250
  SERVER_MAX_VALUE_LENGTH = 1048576

Imports: sys, socket, time, types, pickle, compress, decompress, crc32, serverHashFunction, local


Function Details

check_key(key, key_extra_len=0)

 

Checks sanity of key. Fails if: Key length is > SERVER_MAX_KEY_LENGTH (Raises MemcachedKeyLength). Contains control characters (Raises MemcachedKeyCharacterError). Is not a string (Raises MemcachedStringEncodingError)