📄 cacheconfig.java
字号:
package cn.myapps.util.cache;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Properties;
import cn.myapps.util.property.DefaultProperty;
public class CacheConfig {
public static CacheConfig _application;
private String providerClassName;
private HashMap methodCacheConfigs = new HashMap();
public static CacheConfig getInstance() throws IOException {
if (_application == null) {
_application = createCacheConfig();
}
return _application;
}
public static void main(String[] args) {
try {
createCacheConfig();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static CacheConfig createCacheConfig() throws IOException {
CacheConfig cconf = new CacheConfig();
Properties prop = new Properties();
InputStream is = CacheConfig.class.getClassLoader()
.getResourceAsStream("myapps-cache.properties");
prop.load(is);
cconf.setProviderClassName(prop.getProperty("providerClassName"));
// prop.keys().
Enumeration enums = prop.keys();
while (enums.hasMoreElements()) {
String key = (String) enums.nextElement();
if (!key.equals("providerClassName")) {
MethodCacheConfig methodcache = new MethodCacheConfig();
methodcache.signature = key;
String[] tmp = prop.getProperty(key).split(",");
methodcache.maxElementsInMemory = Integer.parseInt(tmp[0]);
methodcache.timeToLiveSeconds = Integer.parseInt(tmp[1]);
methodcache.timeToIdleSeconds = Integer.parseInt(tmp[2]);
cconf.getMethodCacheConfigs().put(key, methodcache);
}
}
return cconf;
}
private CacheConfig() {
}
public String getProviderClassName() {
return providerClassName;
}
public void setProviderClassName(String providerClassName) {
this.providerClassName = providerClassName;
}
public HashMap getMethodCacheConfigs() {
return methodCacheConfigs;
}
public void setMethodCacheConfigs(HashMap methodNames) {
this.methodCacheConfigs = methodNames;
}
}
class MethodCacheConfig {
String signature;
int maxElementsInMemory;
int timeToLiveSeconds;
int timeToIdleSeconds;
public int getMaxElementsInMemory() {
return maxElementsInMemory;
}
public void setMaxElementsInMemory(int maxElementsInMemory) {
this.maxElementsInMemory = maxElementsInMemory;
}
public int getTimeToIdleSeconds() {
return timeToIdleSeconds;
}
public void setTimeToIdleSeconds(int timeToIdleSeconds) {
this.timeToIdleSeconds = timeToIdleSeconds;
}
public int getTimeToLiveSeconds() {
return timeToLiveSeconds;
}
public void setTimeToLiveSeconds(int timeToLiveSeconds) {
this.timeToLiveSeconds = timeToLiveSeconds;
}
/**
* @hibernate.property column="SIGNATURE"
*/
public String getSignature() {
return signature;
}
public void setSignature(String signature) {
this.signature = signature;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -