java - Caching data using collection -
so, have issue caching data inside java collection. when initialize app first time use below function this,
cacheimageandsounds(0,6); now once reach 4th position start want remove previous 3 elements collection , cache next 3 i.e.
cacheimageandsounds(4,10); but have 4th, 5th , 6th image in cache won't want re-bring them inside cache present, hence download or fetch 7th 10th image , sound files.
how can go doing this, or how may tweak algorithm of caching data inside map?
this function use create cache of images , sound files inside collection , use further retrieve data it, based on various index values. use in way knowingly can set 2 indexes , required data filled inside collection.
public int cacheimageandsounds(int startindex,int lastindex) { for(int i=startindex;i<lastindex;i++) { aq.ajax(data1.get(i), bitmap.class, new ajaxcallback<bitmap>() { @override public void callback(string url, bitmap object, ajaxstatus status) { imagefilexxs.put(url, object); system.out.println("size of imagefile"+imagefilexxs.size()); } }); aq.ajax(data1.get(i).replace(".png", ".mp3"), file.class, new ajaxcallback<file>() { @override public void callback(string url, file object, ajaxstatus status) { imagefilexxsm.put(url, object); system.out.println("size of songfile"+imagefilexxsm.size()); if(imagefilexxsm.size()>=6) { update(); //call ui } } }); } return 1; } clear cache , build new one.
public void clearcachelogic() { imagefilexxs.clear(); imagefilexxsm.clear(); }
looks not caching index , checking it, before making ajax call. have new set<integer> called processed. , method like,
public int cacheimageandsounds(int startindex,int lastindex) { for(final int i=startindex;i<lastindex;i++) { //check if index processed, if not make call if(!processed.contains(i)) { aq.ajax(data1.get(i), bitmap.class, new ajaxcallback<bitmap>() { @override public void callback(string url, bitmap object, ajaxstatus status) { imagefilexxs.put(url, object); system.out.println("size of imagefile"+imagefilexxs.size()); processed.add(i); //once result comes, mark index processed } }); aq.ajax(data1.get(i).replace(".png", ".mp3"), file.class, new ajaxcallback<file>() { @override public void callback(string url, file object, ajaxstatus status) { imagefilexxsm.put(url, object); processed.add(i); //once result comes, mark index processed system.out.println("size of songfile"+imagefilexxsm.size()); if(imagefilexxsm.size()>=6) { update(); //call ui } } }); } } return 1; } in way, when call cacheimageandsounds(4,10);, 4th, 5th , 6th index, no ajax call made since these indices present in processed set
Comments
Post a Comment