欢迎来到天天文库
浏览记录
ID:16752686
大小:23.00 KB
页数:3页
时间:2018-08-24
《spring用单例模型做高速缓存》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、Spring高速缓存先来一个单例模型,里面的重点是有一个map,可以获取内存空间。单例模型的话,可以自己访问自己,内部数据,不会被垃圾回收机制回收。@ComponentpublicclassAutoReplyCache{privatestaticHashMapcacheMap;@AutowiredprivateAutoreplyListServiceautoreplyListService;privatestaticAutoReplyCachearcache;privatebyte[]lock=n
2、ewbyte[0];publicstaticAutoReplyCachegetInstance(){if(arcache==null){arcache=newAutoReplyCache();}returnarcache;}publicAutoReplyCache(){}publicsynchronizedvoidloadAll(){System.out.println("====="+"得到缓存========");cacheMap=newHashMap();List3、>arlistlist=autoreplyListService.getList();if(arlistlist!=null){setCacheMap(arlistlist);}System.out.println("==="+"得到缓存完毕=====");}publicsynchronizedvoidreloadAll(){System.out.println("===="+"重新得到缓存=====");Listarlistlist=autoreplyListService.getList();4、if(arlistlist!=null){cacheMap.clear();setCacheMap(arlistlist);ofwork,relationships,needandpossibility,putqualityfirst."Improvestructure",referspartycarefully".IsamustadheretotheindividualabsorptionTheprincipleofthedevelopmentofamatureone,andstrictlyperformintheadmis5、sionprocedure,topreventthePartymember}System.out.println("===="+"重新得到缓存=====");}privatevoidsetCacheMap(Listarlistlist){for(AutoreplyListarlist:arlistlist){cacheMap.put(String.valueOf(arlist.getNum()),arlist);}}publicsynchronizedvoidadd(AutoreplyListar6、list){cacheMap.put(String.valueOf(arlist.getNum()),arlist);}publicsynchronizedvoidupdate(AutoreplyListarlist){cacheMap.put(String.valueOf(arlist.getNum()),arlist);}publicsynchronizedAutoreplyListfindarlistByID(Stringid){if(cacheMap.values()!=null&&cacheMap.values().7、size()>0){for(Iteratoriter=cacheMap.values().iterator();iter.hasNext();){AutoreplyListarlist=(AutoreplyList)iter.next();if(id.equals(String.valueOf(arlist.getId()))){returnarlist;}}}returnnull;}publicsynchronizedListgetallCache(){Listli8、stAll=newArrayList();for(Iteratoriter=cacheMap.values().iterator();iter.hasNext();){AutoreplyListarlist=(AutoreplyList)iter
3、>arlistlist=autoreplyListService.getList();if(arlistlist!=null){setCacheMap(arlistlist);}System.out.println("==="+"得到缓存完毕=====");}publicsynchronizedvoidreloadAll(){System.out.println("===="+"重新得到缓存=====");Listarlistlist=autoreplyListService.getList();
4、if(arlistlist!=null){cacheMap.clear();setCacheMap(arlistlist);ofwork,relationships,needandpossibility,putqualityfirst."Improvestructure",referspartycarefully".IsamustadheretotheindividualabsorptionTheprincipleofthedevelopmentofamatureone,andstrictlyperformintheadmis
5、sionprocedure,topreventthePartymember}System.out.println("===="+"重新得到缓存=====");}privatevoidsetCacheMap(Listarlistlist){for(AutoreplyListarlist:arlistlist){cacheMap.put(String.valueOf(arlist.getNum()),arlist);}}publicsynchronizedvoidadd(AutoreplyListar
6、list){cacheMap.put(String.valueOf(arlist.getNum()),arlist);}publicsynchronizedvoidupdate(AutoreplyListarlist){cacheMap.put(String.valueOf(arlist.getNum()),arlist);}publicsynchronizedAutoreplyListfindarlistByID(Stringid){if(cacheMap.values()!=null&&cacheMap.values().
7、size()>0){for(Iteratoriter=cacheMap.values().iterator();iter.hasNext();){AutoreplyListarlist=(AutoreplyList)iter.next();if(id.equals(String.valueOf(arlist.getId()))){returnarlist;}}}returnnull;}publicsynchronizedListgetallCache(){Listli
8、stAll=newArrayList();for(Iteratoriter=cacheMap.values().iterator();iter.hasNext();){AutoreplyListarlist=(AutoreplyList)iter
此文档下载收益归作者所有