On Sep 11, 9:33 pm, realdope <[email protected]> wrote:
> Here's rest of the code:
>
>     private static boolean has(String key) {
>         return MemcacheServiceFactory.getMemcacheService().contains(key) &&
> get(key).length()>0;
>     }
>
...
>         if (Memcache.hasById(id)) return Memcache.getById(id);
>  

This code is slower than it should be, since it does 3 consecutive
requests to memcache. (two in has() and then one in getById())
Also it has a problem, because the value could drop out of memcache
after the has() and then getById returns null.

Just write it like this.

String res = Memcache.getById(id);
if (res == null) {
        res = V1Post.getById(id);
        Memcache.putById(id, res);
}
return res;

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to