I think I may have found a bug in JCS with regards to the IdleTime element attribute. Either that or I don't understand how this setting works.
If something is put in the cache and not retrieved until after more than IdleTime seconds, then JCS is supposed to throw the item out of the cache and return null when asked to get() the item right? Below is a sample JUnit test that shows five items being put in JCS and not accessed again until long after the IdleTime interval has passed. The items are still accessible and the CompositeCache's getMissCountExpired() method returns zero when I think it should return five. Is this a bug? I am using JCS 1.2.7.9 to do this test. ====================================================================================== package bugtest; import java.util.Properties; import org.apache.jcs.JCS; import org.apache.jcs.engine.behavior.IElementAttributes; import org.apache.jcs.engine.control.CompositeCache; import org.apache.jcs.engine.control.CompositeCacheManager; import junit.framework.TestCase; public class TestMissCountExpiredBug extends TestCase { public void testSomething() throws Exception { // setup JCS CompositeCacheManager mgr = CompositeCacheManager.getUnconfiguredInstance(); mgr.configure( setupProperties() ); // get access to bug test cache region JCS jcs = JCS.getInstance( "BugTest" ); CompositeCache cache = mgr.getCache( "BugTest" ); // put five items in cache for ( int i = 0; i < 5; i++ ) { String key = "key" + i; String value = "value" + i; jcs.put( key, value ); } // sleep for twice the length of the max idle time of items in the cache // region IElementAttributes attrs = cache.getElementAttributes(); long idleTimeSeconds = attrs.getIdleTime(); assertEquals( 5L, idleTimeSeconds ); System.out.println( "idle time seconds=" + idleTimeSeconds ); long sleepTime = 1000 * 2 * idleTimeSeconds; System.out.println( "sleeping for " + sleepTime + " millis to allow cache elements to be flagged as idle for too long" ); Thread.sleep( sleepTime ); // try to access the five items - they should have expired so this should // fail for ( int i = 0; i < 5; i++ ) { String key = "key" + i; Object value = jcs.get( key ); if ( value != null ) { System.out.println( "found a value for key " + key + ": " + value ); } } // check miss count expired - should be five int missCountExpired = cache.getMissCountExpired(); System.out.println( "miss count expired: " + missCountExpired ); assertEquals( 5, missCountExpired ); } private Properties setupProperties() { Properties answer = new Properties(); // defaults answer.setProperty( "jcs.default", "" ); answer.setProperty( "jcs.default.cacheattributes", "org.apache.jcs.engine.CompositeCacheAttributes" ); answer.setProperty( "jcs.default.cacheattributes.MemoryCacheName", "org.apache.jcs.engine.memory.lru.LRUMemoryCache" ); answer.setProperty( "jcs.default.cacheattributes.MaxObjects", "100000" ); // bug test region - elements won't go to disk, but should be marked as expired after five seconds of non-use answer.setProperty( "jcs.region.BugTest", "" ); answer.setProperty( "jcs.region.BugTest.cacheattributes", "org.apache.jcs.engine.CompositeCacheAttributes" ); answer.setProperty( "jcs.region.BugTest.cacheattributes.MemoryCacheName", "org.apache.jcs.engine.memory.lru.LRUMemoryCache" ); answer.setProperty( "jcs.region.BugTest.cacheattributes.MaxObjects", "1000" ); answer.setProperty( "jcs.region.BugTest.cacheattributes.UseMemoryShrinker", "false" ); answer.setProperty( "jcs.region.BugTest.elementattributes", "org.apache.jcs.engine.ElementAttributes" ); answer.setProperty( "jcs.region.BugTest.elementattributes.IsEternal", "false" ); answer.setProperty( "jcs.region.BugTest.elementattributes.IdleTime", "5" ); return answer; } } ____________________________________________________________________________________ Now that's room service! Choose from over 150,000 hotels in 45,000 destinations on Yahoo! Travel to find your fit. http://farechase.yahoo.com/promo-generic-14795097 --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]