4 Replies Latest reply on Jul 7, 2014 9:45 AM by david.novak

    Get random object from cache

    david.novak

      Hi,

      I need to get one random object (or key) from my Infinispan cache - does anybody have a hint? Of course, I do not want to retrieve all keys (entries) from the cache (because it would load all keys to memory). I don't mind if the entry (key) will be only from the local Insp node.

      Thanks for anything!

       

      David

        • 1. Re: Get random object from cache
          wdfink

          I don't understand your requirement.

          What you mean by random? You can't get data from the cache without knowing the key

          • 2. Re: Get random object from cache
            david.novak

            I need to do something like this:

            return cache.get(cache.keySet().iterator().next());

            but ideally in a more efficient way... Thank for any suggestion!

            • 3. Re: Get random object from cache
              wdfink

              I still don't understand the purpose.

              As I said you can't get a value without knowing the key.

               

              If you have such requirement you might add a special entry as cursor and store soemthing like 'first, last, current' and link the key-value objects in the case with additional information previous-next.

              Does that makes sense to you?

              • 4. Re: Get random object from cache
                david.novak

                I am building an application that uses the "query-by-example" paradigm and, in general, I need the data object to issue a query. The key-value store maintains data objects based on their unique IDs (ID-object) and, mainly for testing purposes, I need to access a random sample of the stored data. Of course I could build some additional indexing structure that would allow a "random" access to the IDs  (either using the K-V store or outside) but I was thinking that may be I could somehow access the local hash-table of Ispn node and implement this operation directly.