Test ehcache

来源:互联网 发布:大学物理实验报告数据 编辑:程序博客网 时间:2024/06/05 22:55
CacheManager manager1 = new CacheManager("src/ehcache.xml");
         Cache memoryOnlyCache = new Cache("testCache", 5000, false, false, 5, 2);
        
         manager1.addCache(memoryOnlyCache);
        
        CacheManager singletonManager = CacheManager.create();
//        Cache memoryOnlyCache = new Cache("testCache", 5000, false, false, 5, 2);
        
        Element element = new Element("key1"+key, "value2");
        System.out.println("key1"+key);
        memoryOnlyCache.put(element);
        Element element1 = new Element("key"+key, "value1");
        memoryOnlyCache.put(element1);
        
        Cache test = singletonManager.getCache("testCache");
        System.out.println(test.get("key1"+key).getValue());
        System.out.println(test.get("key"+key).getValue());
        System.out.println(test.getSize());
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        if(test.get("key1"+key)== null){
            System.out.println("null");
        }
        
        
        System.out.println("--"+test.getSize());
        System.out.println(test.get("key1"));
原创粉丝点击