android - How can I clear cache of my app automatically after 1 hr -


i working on story application. in application download json data server , these data should saved in cache. stored data in cache want delete cache after particular time limit.

my code adding data in cache follows:

objectoutput out = new objectoutputstream(new fileoutputstream(new file(getactivity().getcachedir(),"")+"cachefile.srl"));  string tetsing = jsonobject_one.tostring();  out.writeobject( tetsing ); 

when call server, receive callback , add entities in local db, can save in shared preferences long current system milliseconds:

long cachetime = system.currenttimemillis(); 

everytime open activity needs call server, before doing request, check time in shared preferences:

if(timeinsharedpreference < system.currenttimemillis() * 1000 * 60 * 60) {     // request     // update db } 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -