Last active
August 29, 2015 14:20
-
-
Save kaiinui/21e01f3666825a493367 to your computer and use it in GitHub Desktop.
KeyBaseCacheDatastoreCallbacks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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