public class UserManager { UserDAO userDAO; LocalCache localCache; public UserDO getUser(String userNick) { UserDO user = (UserDO)localCache.get(userNick); if(user == null) { user = userDAO.getUser(userNick); if(user != null) { localCache.put(userNick,user); } } return user; } }
public class NullValueResultDO implements Serializable{ private static final long serialVersionUID = -6550539547145486005L; } public class UserManager { UserDAO userDAO; LocalCache localCache; public UserDO getUser(String userNick) { Object object = localCache.get(userNick); if(object != null) { if(object instanceof NullValueResultDO) { return null; } return (UserDO)object; } else { User user = userDAO.getUser(userNick); if(user != null) { localCache.put(userNick,user); } else { localCache.put(userNick, new NullValueResultDO()); } return user; } } }
原文地址:http://blog.csdn.net/troy__/article/details/40829295