2 Replies Latest reply on Jul 19, 2010 3:43 AM by galder.zamarreno

    Cache.isEmpty() returns wrong result

    tolusha

      I have simple test with not understandable cache behavior. After putting value with 2s lifespan I guess that cache should be empty, but it is not right. With using CachLoader I see that DB not empty and stores value.

       

      But if before cache.isEmpty() call cache.containsKey("key") then cache.isEmpty() returns correct result.

       

      public void testCacheLoader() throws Exception
      {


      // Create cache manager
      GlobalConfiguration myGlobalConfig = new GlobalConfiguration();
      EmbeddedCacheManager manager = new DefaultCacheManager();


      // Create a cache
      Cache cache = manager.getCache();


      cache.put("key", "value", 2, TimeUnit.SECONDS);
      assertTrue(cache.containsKey("key"));
      Thread.sleep(10000 + 500);
      assertFalse(cache.isEmpty());
      }