Tuesday 15 February 2011

android - Understanding Memcache -



android - Understanding Memcache -

i newbie android developer. trying build app engine based application. create work on realised need utilize memcache optimize database accesses. have bad time understanding basic concepts. questions follows:

is memcache programming app engine? there nil android side? (i mean if coding needed @ android application?) i used jpa programme app engine app. can utilize low level api memcache?

i got illustration on book usses many http references. type of illustration usable android app or websites' usage?.

public class etagcacheservlet extends httpservlet { private static final long serialversionuid = 4308584640538822293l; public void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { memcacheservice cache = memcacheservicefactory .getmemcacheservice(); string cachekey = request.getrequesturi() + "." + "etag"; string result; if (!cache.contains(cachekey) || !cache.get(cachekey).equals(request .getheader("if-none-match"))) { string etag = long.tostring(system.currenttimemillis()); response.setheader("etag", etag); cache.put(cachekey, etag); result = "loaded cache @ " + (new date()); response.getwriter().write(result); } else { response.setstatus(304); } } }

do know source has working sample app or something?

maybe laugh reading these questions cannot figure these things out. in advance.

edit: tried add together memcache code unsuccessfully, can take @ code please?

@suppresswarnings({ "unchecked", "unused" }) @apimethod(name = "querydesire") public collectionresponse<desire> querydesire( @nullable @named("cursor") string cursorstring, @nullable @named("limit") integer limit, @nullable @named("first") integer first, @nullable @named("name") string name){ entitymanager mgr = null; cursor cursor = null; list<desire> execute = null; seek { string keydesire = "mem_" + name; list<desire> memdesire = (list<desire>) memcache.get(keydesire); if (memdesire == null) { mgr = getentitymanager(); query query2 = mgr.createquery("select want i.ctgry = :name "); if (cursorstring != null && cursorstring != "") { cursor = cursor.fromwebsafestring(cursorstring); query2.sethint(jpacursorhelper.cursor_hint, cursor); } if (limit != null) { query2.setfirstresult(first); query2.setmaxresults(limit); } execute = (list<desire>) query2.setparameter("name", name).getresultlist(); cursor = jpacursorhelper.getcursor(execute); if (cursor != null) cursorstring = cursor.towebsafestring(); (desire obj : execute) ; collectionresponse.<desire> builder().setitems(execute) .setnextpagetoken(cursorstring).build(); memcache.put("mem_cache", querydesire); } homecoming collectionresponse.<desire> builder().setitems(execute) .setnextpagetoken(cursorstring).build(); } { mgr.close(); } }

memcache used on server-side, i.e. app engine. used speed responses server client, not related client code. in other words, no changes necessary on client side if utilize memcache on app engine side.

yes, can utilize low-level api memcache.

see response question 1. memcache can used regardless of how app communicates server.

memcache used in many different ways, may need post specific question, , may able help. meanwhile, here illustration code. time zones required app, , never change. makes sense utilize memcache speed response.

private static final memcacheservice memcache = memcacheservicefactory.getmemcacheservice(); public static arraylist<string> gettimezones() { arraylist<string> timezones = (arraylist<string>) memcache.get("time_zones"); if (timezones == null) { // method reads time zones properties file timezones = preparetimezones(); memcache.put("time_zones", timezones); } homecoming timezones; }

android google-app-engine memcached

No comments:

Post a Comment