I'm currently working on adding memcache to an app running on GAE/J. I have a question about how production memcache behaves when values expire, if they're keys are also removed.
The closest I could find to answering this question is here: http://code.google.com/appengine/docs/java/memcache/overview.html#How_Cached_Data_Expires
I know I can't rely on values staying in memcache; and I don't, but what I am wondering, is if the keys which map to those values are also removed.
In other words, if I do
mycache.contains("key")
Will this still be true after a value is pushed out of the cache?
Side note: Don't think it makes a difference; but just in case, I'm using the async memcache from the memcache service and get a hold of it like this:
MemcacheServiceFactory.getAsyncMemcacheService();
I'm asking this because I'm not doing the typical
if(cache.get("key") == null)
I store null values when they come back from the datastore so I don't constantly lookup the null value. And I do take care to make sure to remove the key when it can possibly change. So just because the memcache lookup returns null, I work on the assumption that the query is in fact null; but I do ensure that when other queries which could change that happen that the null lookup gets removed. That is why I'm using cache.contains("key")
as opposed to cache.get("key") == null
Your assumption is correct, mycache.contains("key")
will return false if the value had been evicted from the memcache service. This behavior is documented in the Javadoc of the low-level Memcache API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With