OsCacheImp.java
资源名称:Myblog.rar [点击查看]
上传用户:wlfwy2004
上传日期:2016-12-12
资源大小:33978k
文件大小:2k
源码类别:
Jsp/Servlet
开发平台:
Java
- package com.opensource.blog.service.cache.imp;
- import org.apache.commons.logging.Log;
- import org.apache.commons.logging.LogFactory;
- import java.util.*;
- import org.springframework.core.io.*;
- import com.opensource.blog.service.cache.Cache;
- import com.opensymphony.oscache.general.*;
- import com.opensymphony.oscache.base.*;
- public class OsCacheImp
- implements Cache {
- private static final Log logger = LogFactory.getLog(OsCacheImp.class);
- private GeneralCacheAdministrator admin;
- public OsCacheImp() {
- admin = new GeneralCacheAdministrator();
- }
- public OsCacheImp(String profile) {
- Properties properties = new Properties();
- ClassPathResource classPathResource = new ClassPathResource(profile);
- try {
- logger.info("Init Cache...");
- properties.load(classPathResource.getInputStream());
- admin = new GeneralCacheAdministrator(properties);
- }
- catch (Exception ex) {
- logger.error(ex);
- admin = new GeneralCacheAdministrator();
- }
- }
- /**
- *
- * @param key Object
- * @param value Object
- * @todo Implement this com.opensource.blog.service.cache.Cache method
- */
- public void add(Object key, Object value) {
- this.admin.putInCache(String.valueOf(key), value);
- }
- /**
- *
- * @param key Object
- * @return java.lang.Object
- * @todo Implement this com.opensource.blog.service.cache.Cache method
- */
- public Object get(Object key) {
- try {
- return this.admin.getFromCache(String.valueOf(key));
- }
- catch (NeedsRefreshException ex) {
- return null;
- }
- }
- /**
- *
- * @param key Object
- * @todo Implement this com.opensource.blog.service.cache.Cache method
- */
- public void remove(Object key) {
- this.admin.flushEntry(key.toString());
- }
- /**
- *
- * @todo Implement this com.opensource.blog.service.cache.Cache method
- */
- public void removeAll() {
- this.admin.flushAll();
- }
- }