首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

对缓存的应用总结

2012-10-11 
对缓存的使用总结对缓存的使用主要是领会它的原理,知道为什么要使用缓存,然后对实现进行了解,有4种缓存的

对缓存的使用总结

对缓存的使用主要是领会它的原理,知道为什么要使用缓存,然后对实现进行了解,有4种缓存的实现,我这里说一下常用的Ehcache缓存;它的精髓就在于ehcache.xml的配置,具体实例和解义如下:

public List<PersonBean> getAllPerson(){ArrayList<PersonBean> persons = null;Cache cache = DwrEhcache.getPersonList();ArrayList<PersonBean> list = new ArrayList<PersonBean>();try {list = (ArrayList<PersonBean>)cache.get("personList").getObjectValue();persons = (ArrayList<PersonBean>)list.clone();} catch (Exception e) {list = null;} if(list == null){persons= new ArrayList<PersonBean>();PersonBean p1 = new PersonBean("Lucy",12,"女");PersonBean p2 = new PersonBean("Jam",13,"男");persons.add(p1);persons.add(p2);Element element = new Element("personList",persons);cache.put(element);System.out.println("手动添加的,不是从缓存中读取的....");}return persons;}

?一些OK,运行DWR项目,成功了、

?

热点排行