?? usercache.java
字號:
package com.laoer.bbscs.sys;
import com.opensymphony.oscache.general.*;
import com.laoer.bbscs.bean.*;
import com.opensymphony.oscache.base.*;
import com.laoer.bbscs.business.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* <p>Title: TianYi BBS</p>
* <p>Description: TianYi BBS System</p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: LAOER.COM/TIANYISOFT.NET</p>
* @author laoer
* @version 6.0
*/
public class UserCache {
private static final Log logger = LogFactory.getLog(UserCache.class);
private static UserCache instance;
private GeneralCacheAdministrator admin;
private IUserInfoService userInfoService;
public synchronized static UserCache getInstance() {
if (instance == null) {
instance = new UserCache();
}
return instance;
}
public synchronized static UserCache getInstance(IUserInfoService
userInfoService) {
if (instance == null) {
instance = new UserCache(userInfoService);
}
return instance;
}
public UserCache() {
this.admin = new GeneralCacheAdministrator();
}
public UserCache(IUserInfoService userInfoService) {
this.admin = new GeneralCacheAdministrator();
this.userInfoService = userInfoService;
}
public void putUserInfoInCache(UserInfo ui) {
logger.debug("Put in UserCache " + ui);
this.admin.putInCache(String.valueOf(ui.getId()), ui);
}
public UserInfo getUserInfoFromCache(long id) {
try {
return (UserInfo)this.admin.getFromCache(String.valueOf(id));
}
catch (NeedsRefreshException ex) {
logger.debug(id + " is not int UserCache,get from DB,put in UserCache.");
UserInfo ui = this.getUserInfoService().findUserInfoById(new Long(id));
if (ui != null) {
this.admin.putInCache(String.valueOf(id), ui);
return ui;
}
else {
return null;
}
}
}
public IUserInfoService getUserInfoService() {
return userInfoService;
}
public void setUserInfoService(IUserInfoService userInfoService) {
this.userInfoService = userInfoService;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -