In Google App Engine, what is the simplest way to keep a record of items that you have put into memc

Posted by Chris Boesch on Stack Overflow See other posts from Stack Overflow or by Chris Boesch
Published on 2010-03-13T02:57:06Z Indexed on 2010/03/13 3:07 UTC
Read the original article Hit count: 352

Filed under:
|

I am starting to use memcache more frequently to avoid having to recalculate things between page requests. When the memcache periodically clears, as it is designed to do, I have to start all over rebuilding various items that I have placed in memcache. What I would like to do is create a very simple model that enables me to periodically save the items that I put into memcache based on the memcache keys that I'm using along with a datetime that is related to the data being memcached. What is the best way to do this?

I'm looking for something like this:

class MemcacheRecord(db.Model):
  key = db.StringProperty(required=True)
  value = #Something that can store whatever memcache can
  validThru = db.DateTimeProperty(required=True)

  def set(self, key, value, validThru):
      #Save a new memcache record
      newMemcacheRecord = MemcacheRecord(key=key, value=value, validThru=validThru)
      ..
      return True # or False

  def get_latest(self, key):
      #Get the memcache record with the most recent validThru datetime
      latestMemcacheRecord = MemcacheRecord.all().order('-validThru').get()
      return {'validThru':latestMemcacheRecord.validThru, 'value':latestMemcachRecord.value}

© Stack Overflow or respective owner

Related posts about google-app-engine

Related posts about memcache