Download and install from: http://memcached.org/ (Google App Engine and many clouds provide this already)
def create_data( name ):
data = Data()
data.name = name
data.put()
memcache.set( 'key', data, 60 )
return data
def get_data():
data = memcache.get( 'key' )
if data is not None:
return data
else:
data = self.query_for_data()
memcache.add( 'key', data, 60 ) # add throws an exception if the key already exists
return data
# TODO: counter example with memcache.incr() or decr()
# TODO: find a way to use append, prepend, cas (compare and set), gets for CAS, ... stats, stats items, etc.
MORE RESOURCES:
https://code.google.com/p/memcached/wiki/NewCommands
http://www.memcachier.com/documentation/memcache-user-guide/