Skip to content

Instantly share code, notes, and snippets.

@kaiinui
Last active August 29, 2015 14:20
Show Gist options
  • Save kaiinui/21e01f3666825a493367 to your computer and use it in GitHub Desktop.
Save kaiinui/21e01f3666825a493367 to your computer and use it in GitHub Desktop.
KeyBaseCacheDatastoreCallbacks
public class KeyBaseCacheDatastoreCallbacks {
@PostPut
public void putToCacheAfterPut(PutContext putContext) {
final Entity entity = putContext.getCurrentElement();
MemcacheServiceFactory.getAsyncMemcacheService().put(entity.getKey(), entity);
}
@PreGet
public void getFromCacheIfHits(PreGetContext getContext) {
final Key key = getContext.getCurrentElement();
final Entity entity = Memcache.get(key);
if (entity != null) {
getContext.setResultForCurrentElement(entity);
}
}
@PostLoad
public void putToCacheAfterGet(PostLoadContext loadContext) {
final Entity entity = loadContext.getCurrentElement();
MemcacheServiceFactory.getAsyncMemcacheService().put(entity.getKey(), entity);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment