JCS-基本配置

来源:互联网 发布:关键词排名优化公司 编辑:程序博客网 时间:2024/05/25 19:56

从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);  }  }}


 

原创粉丝点击