⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usercache.java

📁 天乙社区6.0是一套基于JAVA技术的网络虚拟社区
💻 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 + -