5 Replies Latest reply on Jan 27, 2006 11:49 AM by anupama oruganti

    How to setup standalone cache w/ an expiration time

    Hong Wu Newbie

      Hi,

      I am trying to test out the expiration/timeout of objects in memory using JBoss Cache. But it seems not working for me.

      My test codes are simply trying to get the value of the object I put in the tree every 5 sec.

      try {
      TreeCache tree = new TreeCache();
      PropertyConfigurator config = new PropertyConfigurator();
      config.configure(tree, "my-config.xml");
      tree.startService();

      tree.put("/test/1/", "5sec", "5 sec test");
      int count = 0;
      boolean run = true;
      while (run) {
      count++;
      if (count==3) run = false;
      String s = (String)tree.get("/fandango/1","5sec");
      System.out.println("s: " + s);
      Thread.sleep(5000);
      }
      tree.stopService();
      } catch (Exception e) {
      e.printStackTrace();
      }

      And in my-config.xml file I have:

      org.jboss.cache.eviction.LRUPolicy



      5
      <!-- Cache wide default -->

      5000
      3
      <!-- Maximum time an object is kept in cache regardless of idle time -->
      5



      1000
      2
      3





      So in theory, the 2nd time when the tree.get() the object, it should return null because it's already expired. But my tests show otherwise.

      Please advise,

      Many thanks,

      Hong