Expire/evict an object from the cache

124 views
Skip to first unread message

Kyle Baley

unread,
Apr 24, 2012, 5:25:33 PM4/24/12
to objectify...@googlegroups.com
We're using the @Cached annotation on some of our entities and have a need to remove items from the cache. There are times when we've had to update data in the datastore viewer for a customer for things we haven't created an admin interface for yet. Also, it's helpful when we're QA testing different scenarios.

What is the format of the key used for entities that are inserted into Memcache? I've tried the AppEngine key for the entity (both on its own and with ObjectifyCache as the prefix). Alternatively, is there a way to evict an object from the cache through Objectify?

Jeff Schnitzer

unread,
Apr 24, 2012, 6:40:15 PM4/24/12
to objectify...@googlegroups.com
There isn't an API call to do this... it's probably a good feature
request though.

Use the MemcacheService namespace "ObjectifyCache" (or the constant
ObjectifyFactory.MEMCACHE_NAMESPACE). Assuming you are running on a
recent version of Objectify, the actual cache key is the native
datastore Key object. If you have a Key<?>, call key.getRaw().

Remember that the cache is implemented at the level of the Low-Level
API. It doesn't know anything about the rest of Objectify, so all
keys and values are Low-Level API classes.

Jeff

Kyle Baley

unread,
Apr 28, 2012, 8:55:03 PM4/28/12
to objectify...@googlegroups.com
Thanks Jeff, I'll do that.

stephanos

unread,
May 14, 2013, 3:11:34 PM5/14/13
to objectify...@googlegroups.com, je...@infohazard.org
I'm having the same need to manually remove an item from Memcache that was put there by Objectify right now.

So maybe there really could be an API for that? Or do you think it's too uncommon?

Jeff Schnitzer

unread,
May 15, 2013, 12:47:44 AM5/15/13
to objectify...@googlegroups.com
It seems a reasonable request; what do you want the API to look like and the behavior to be (evict from session, memcache, both)? 

BTW as of 4.0b3, the cache is keyed by the string version of the key. That is, the cache key is Key.getString(). The old cache key was a raw Key, which it turns out is a lousy cache key - GAE serializes it (with java serialization) and takes a hash of it.

Jeff


--
You received this message because you are subscribed to the Google Groups "objectify-appengine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to objectify-appen...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

stephanos

unread,
May 15, 2013, 3:43:41 AM5/15/13
to objectify...@googlegroups.com, je...@infohazard.org
Hm, good question, maybe:

dataStore.get.save().clearCache().entity(source)

I can't image why one would want to clear only one cache and not both. 
To unsubscribe from this group and stop receiving emails from it, send an email to objectify-appengine+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages