john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

memcache intro

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/

  • « server chat improved example
  • google app engine cost and performance optimization »

Published

May 1, 2013

Category

python

~88 words

Tags

  • intro 9
  • memcache 2
  • python 180