Memcache mixin for datastore models
So we made a datastore model mixin that will transparently use memcache. It is available on Google Code under the MIT license, just like the rest of pageforest.com: http://code.google.com/p/pageforest/source/browse/appengine/utils/cacheable.py
To use it, just inherit your model from it:
from google.appengine.ext import db from utils.mixins import Cacheable class App(Cacheable): name = db.StringProperty()
The interesting part is that it automatically reduces datastore write contention by skipping datastore put if the write rate is consistently high. The App Engine datastore only supports 5 updates per second. So if one entity gets 10 updates per second, the Cacheable mixin makes sure that it's always saved to memcache but the datastore is updated only once every 2 seconds.