4 Replies Latest reply on Dec 28, 2012 9:51 AM by kovica1

    Maintaining insertion order

    kovica1

      Hi!

       

      I'm using Infinispan 5.0.1. and I want that I get values from the cache in the same order as I put them in.

      For example:

      Cache<String, String> myCache = defaultCacheManager.getCache("myCache");
      myCache.put("1", "ONE");
      myCache.put("2", "TWO");
      myCache.put("3", "THREE");
      myCache.keySet();
      Set<String> keySet = myCache.keySet();
      for (String key : keySet) {
          System.out.println(myCache.get(key));
      }

       

      This should print out:

      ONE

      TWO

      THREE

       

      Similar to LinkedHashMap in Java. How do I do it?

       

      Best regards,

          Kovi

        • 1. Re: Maintaining insertion order
          vblagojevic

          Hey,

           

          keySet() operation does not have in its API contract an obligation to return set items in insertion order.

           

          Regards,

          Vladimir

          • 2. Re: Maintaining insertion order
            kovica1

            Hi!

             

            Yes, that is correct.

            It's just that I'm using Infinispan for all my other projects and I wanted to use it also for this one.

            Because in this one I need just that, insertion order. LinkedHashMap provides it, so I found a ConcurrentLinkedHashMap on Google code, which is perfect for my needs.

            The main Infinispan interface, org.infinispan.Cache, extends ConcurrentMap, which does not support insertion order, right?

            Is there a way to make Infinispan use my cache implementation based on LinkedHAshMAp, not ConcurrentMap?

             

            Best regards,

                Kovi

            • 3. Re: Maintaining insertion order
              vblagojevic

              Hey, unfortunately not. We do not support it now and I doubt it will be supported any time soon. If I was in your position I would go for plan B :-)

               

              Cheers,

              Vladimir

              • 4. Re: Maintaining insertion order
                kovica1

                Hi!

                 

                Yes, I did do that.

                 

                Thanks for your help.

                 

                Best regards,

                    Kovi