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}