读书人

对缓存的应用总结

发布时间: 2012-10-11 10:16:10 作者: rapoo

对缓存的使用总结

对缓存的使用主要是领会它的原理,知道为什么要使用缓存,然后对实现进行了解,有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项目,成功了、

?

读书人网 >软件架构设计

热点推荐