java - Android - only calling a method every 15 minutes max, and using saved data otherwise -



java - Android - only calling a method every 15 minutes max, and using saved data otherwise -

i'm writing app method accessing info online. however, maximally allowed query website @ 1 time every 15 minutes. if 15 minutes has not elapsed, want utilize info recent query. best practices checking lastly time method called?

just utilize cache 20 min expiration , should go. prefer existing 1 implementing own, 1 field it's trivial - time when retrieve resource , add together 20 minutes. if current time after can again,

date cachedat = null; string cachedcontent = null; string getcachedthing() { if (cachedcontent != null && cachedat != null && new date().before(cachedat)) { homecoming cachedcontent; } getthing(); homecoming cachedcontent; } private void getthing() { // resource. calendar cal = calendar.getinstance(); cal.add(calendar.minute, 20); cachedat = cal.gettime(); cachedcontent = "mywebpage"; }

java android methods

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -