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

    How to setup standalone cache w/ an expiration time

    lordhong2

      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

        • 1. Re: How to setup standalone cache w/ an expiration time
          lordhong2

          here's the my-config again...

          attribute name="EvictionPolicyClass" org.jboss.cache.eviction.LRUPolicy attribute

          attribute name="EvictionPolicyConfig"
          config
          attribute name="wakeUpIntervalSeconds" 5 /attribute
          region name="/_default_"
          attribute name="maxNodes" 5000 /attribute
          attribute name="timeToLiveSeconds" 3 /attribute
          attribute name="maxAgeSeconds" 5 /attribute
          /region

          region name="/test/1"
          attribute name="maxNodes" 1000 /attribute
          attribute name="timeToLiveSeconds" 2 /attribute
          attribute name="maxAgeSeconds" 3 /attribute
          /region

          /config
          /attribute

          • 2. Re: How to setup standalone cache w/ an expiration time
            lordhong2

            argh... i cannot edit my post...

            this line:
            String s = (String)tree.get("/fandango/1","5sec");
            should be:
            String s = (String)tree.get("/test/1","5sec");

            • 3. Re: How to setup standalone cache w/ an expiration time

              maxAgeSeconds has been deprecated long time ago (since 1.2) for timeToLiveSeconds.

              Try to run the junit test under the distro. Under evict, it has numerous examples illustrating the eviction policy expiration test.

              -Ben

              • 4. Re: How to setup standalone cache w/ an expiration time
                lordhong2

                Thank you!
                I found my problem was with "wakeUpIntervalSeconds" value being set too long.

                Rock On!

                • 5. Re: How to setup standalone cache w/ an expiration time
                  anupama

                  Hi Guys.

                  I am trying to use JBoss Tree Cache AOP for caching startup data, so my question is is it by default configured for Clustered environment, if not what I have to do for clustered environment. Moreover if I am able to use TreeCacheAOP without starting JBoss server, it's not giving me feeling that cache resides in server I know I am totally wrong but I amn't able to get clear picture of JBoss Tree Cache AOP, can you guys point me to a place where I can get clear picture.

                  Thanks alot,
                  Anu