📄 oscacheimp.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();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -