这是一个本地缓存类,在程序启动时如果它是第一次通过key访问,直接获取,第二次访问的时候会缓存在本地
private List<Student> dicList;
private static ConcurrentMap<String, List<Student>> cacheStudent = new ConcurrentHashMap<String, List<Student>>();
//缓存的初始化
public void init(String key){
try {
dicList = cacheStudent.get(key);
if(dicList==null){
dicList = createStudentList();
cacheStudent.put(key,dicList);
}
} catch (Exception e) {
e.printStackTrace();
dicList = null;
}
}
public List<Student> createStudentList(){
Student s = new Student();
s.setId("1");
s.setName("2");
dicList.add(s);
return dicList;
}