1
votes

We are going to implement gemfire for our project. We are currently syncing gemfire cache with our DB2 database. So, we are facing issue while putting DB data into cache.

To put DB data into region. I have implement com.gemstone.gemfire.cache.CacheLoader and override load method of it. As written in java doc load method will return only one Object. But for our requirement we will have to return multiple VO from load method

public List<CmDvceInvtrGemfireBean> load(LoaderHelper<CmDvceInvtrGemfireBean, CmDvceInvtrGemfireBean> helper)
            throws CacheLoaderException

While returining multiple VO in form of List<CmDvceInvtrGemfireBean> gemfire region consider it's as single value.

So, when i invoke,

System.out.println("return COUNT" + cmDvceInvtrRecord.query("SELECT COUNT(*) FROM /cmDvceInvtrRecord"));

It return count of one. But i can see total 7 number of data into it.

So, I want to implement the kind of mechanism that will put all the 7 values as a separate VO in Region

Is there any way to do this using Gemfire CacheLoader?

1

1 Answers

0
votes

A CacheLoader was meant to load a value only for a single entry in the GemFire Region on a cache miss. As the Javadoc states...

..creates the value for the desired key..

While a key can map to a multi-valued (e.g. an array/Collection) value, the CacheLoader can only populate a single entry.

You will have to resort to other means of populating the cache with multiple "entries" in a single operation.

Out of curiosity, why do you need (requirement?) to load multiple entries (from the DB) at once? Are you trying to minimize the number of round trips to the DB?

Also, what logic are you using to decide what VO from the DB will be loaded based on the information (i.e. key) provided in the CacheLoader?

For instance, are you somehow trying to predictably select values from the DB based on the CacheLoader key that would subsequently minimize cache misses on future Region.get(key) calls?

Sorry, I don't have a better answer for you right now, but answers to some of these questions may help me give you some ideas for alternatives.

Cheers, John