1 Reply Latest reply on Mar 19, 2012 5:27 AM by galder.zamarreno

    Eviction maxEntries attribute

    bevans88

      Hi,

       

      I'm currently investigating the evitction policies available in Infinispan and have noticed some unexpected(?) functionality in regards to setting maxEntries.

      If i set maxEntries to 10, and then add 10 entries to the cache only 7 of them will remain in the cache, with 3 apparently being evicted. I would expect for all 10 to remain in the cache... The code for this basic test is below (I have tried with a configuration xml as well and have had the same results)

       

         public static void main(String[] args) throws Exception {

       

              EmbeddedCacheManager manager = new DefaultCacheManager();

       

              manager.defineConfiguration("eviction-cache", new ConfigurationBuilder()

                      .eviction().strategy(EvictionStrategy.LIRS).maxEntries(10)

                      .build());

          

              Cache<Object, Object> evictionC = manager.getCache("eviction-cache");

       

              int counter = 0;

              while (counter < 10) {

                  evictionC.put("key" + counter, "" + counter);

                  counter++;

              }

             

              System.out.println(evictionC.size());

              System.out.println(evictionC.values());

          }

       

      This results in the following being output into the console:

       

      7 (size)

      [9, 8, 7, 4, 0, 5, 3] (values)

       

      Any help with this would be appreciated.

       

      Thanks,

       

      Brent