从apache checkout出源码之后,把src/experimental下面的文件夹复制到eclipse工程的src下面。
需要的jar:
HelloJCS.java
public class HelloJCS {
public static void main(String[] args) throws CacheException, FileNotFoundException, IOException{
CompositeCacheManager ccm = CompositeCacheManager.getUnconfiguredInstance();
Properties props = new Properties();
props.load(new FileInputStream(new File("./conf/cache.ccf")));//指定配置文件
ccm.configure(props);
// Initialize the JCS object and get an instance of the default cache region
JCS<String,String> cache = JCS.getInstance("default");
// Set up
String key = "key0";
String value = "value0";
// Place a new object in the cache
cache.put(key, value);
// Retrieve a cached object
String cachedData = (String)cache.get(key);
// Check if the retrieval worked
if (cachedData != null) {
// The cachedData is valid and can be used
System.out.println("Valid cached Data: " + cachedData);
}
}
}