?? cachefactory.java
字號:
package zhouyouguo.slack;
public class CacheFactory {
private static ICacheInterface cache = null;
/** *//**
* 獲取caches指定的緩存
*
* @param caches
* @return
*/
public static ICacheInterface getCacheInstance(Class caches){
if(cache==null){
try {
cache = (ICacheInterface) caches.newInstance();
} catch (InstantiationException e) {
System.out.println("指定的緩存類有誤,caches參數必須是ICacheInterface的實現類");
e.printStackTrace();
} catch (IllegalAccessException e) {
System.out.println("指定的緩存類有誤,caches參數必須是ICacheInterface的實現類");
e.printStackTrace();
}
}
return cache;
}
public static ICacheInterface getDefaultCache(){
if(cache==null){
cache = new DefaultCache();
}else if(!(cache instanceof DefaultCache)){
cache = new DefaultCache();
}
return cache;
}
public static void main(String[] args) {
ICacheInterface cache = CacheFactory.getDefaultCache();
if(cache.contains("area1")){
System.out.println(cache.get("area"));
}else{
cache.Insert("area1","福州1",10);
cache.Insert("area9","福州99999999999999",100);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -