The javadocs for MemcacheService suggest a pattern that you would use
if the
backing cache used soft references:

foo = memcache.get("key");
   if (foo == null) {
     if (memcache.contains("key")) {
       // continue, assuming foo had the real value null
     } else {
       // continue; foo may have had a real null, but has been dropped
now
     }
   }


On Sep 11, 12:33 pm, realdope <rte...@gmail.com> wrote:
> Here's rest of the code:
>
> public class Memcache {
>     private static int EXPIRY = 60*60*24*30;
>     private static final String POSTIDKEY="POSTID_";
>
>     private static boolean has(String key) {
>         return MemcacheServiceFactory.getMemcacheService().contains(key) &&
> get(key).length()>0;
>     }
>
>     private static String get(String key) {
>         try {
>             return (String)
> MemcacheServiceFactory.getMemcacheService().get(key);
>         } catch (Exception e) { return "";    }
>     }
>
>     private static void put(String key, String value, int expiry) {
>         MemcacheServiceFactory.getMemcacheService().put(key, value,
> Expiration.byDeltaSeconds(expiry));
>     }
>
>     private static void delete(String key) {
>         MemcacheServiceFactory.getMemcacheService().delete(key);
>     }
>
>     public static boolean hasById(Long id) { return has(POSTIDKEY+id); }
>     public static String getById(Long id) { return get(POSTIDKEY+id); }
>     public static void putById(Long id, String value) { put(POSTIDKEY+id,
> value, EXPIRY); }
>     public static void flushById(Long id) { delete(POSTIDKEY+id); }
>
> }
>
>     public static String byid(HttpServletRequest req) {
>         Long id=0L;
>         try { id=Long.parseLong(req.getParameter("id")); } catch (Exception
> e) {}
>         if (id==0) return "";
>         if (Memcache.hasById(id)) return Memcache.getById(id);
>         String res = V1Post.getById(id);
>         Memcache.putById(id, res);
>         return res;
>     }
>
> Does anyone know where the error is in my code? And why Memcache.hasById(id)
> seems to always return false?

-- 
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 google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to