public static void main(String args[]) {

    Map<Object, Element> map = new HashMap<Object, Element>();
    List<String> list = new ArrayList<String>();

    // Create a cache manager
    CacheManager cacheManager = CacheManager.getInstance();

    // Creates a cache called newCache
    cacheManager.addCache("newCache");

    // Get cache called newCache
    Cache cache = cacheManager.getCache("newCache");
    StatisticsGateway stats = cache.getStatistics();

    // put into cache
    cache.put(new Element("1", "Monday"));
    list.add("1");
    cache.put(new Element("2", "Tuesday"));
    list.add("2");
    cache.put(new Element("3", "Wednesday"));
    list.add("3");
    cache.put(new Element("4", "Thursday"));
    list.add("4");

    // Displaying all elements
    System.out.println("All elements");
    map = cache.getAll(list);
    Iterator it = map.entrySet().iterator();
    while (it.hasNext()) {
      Map.Entry pair = (Map.Entry) it.next();
      System.out.println(pair.getKey() + " = " + pair.getValue());
    }

    // Displaying elements and size of cache
    Element element = cache.get("1");
    System.out.println("Value of key 1 :" + element.getObjectValue().toString());
    System.out.println("Cache Size " + cache.getSize());
    element = cache.get("2");
    System.out.println("Value of key 2 :" + element.getObjectValue().toString());
    System.out.println("Cache Size " + cache.getSize());
    cache.removeElement(element);
    System.out.println("Cache Size after removing an element : " + cache.getSize());
    cache.flush();
    System.out.println("Removed Cache with key 3 :" + cache.remove("3"));
    System.out.println("Size after remove : " + cache.getSize());
  }
예제 #2
0
  @Test
  public void persistantTest() {
    initCache();

    WorldChunk chunk = testEnv.getWorldLayer(0).get_cached_chunk(0, 0);
    Element element = new Element(1, chunk);
    persistantCache.put(element);

    persistantCache.flush();
    cacheManager.shutdown();

    initCache();

    int diskStore = persistantCache.getDiskStoreSize();
    Assert.assertEquals(diskStore, 1);

    Element persistantElem = persistantCache.get(1);
    WorldChunk persChunk = (WorldChunk) persistantElem.getValue();
  }
 public void flush() {
   cache.flush();
 }