1

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?

John Blum
  • 7,381
  • 1
  • 20
  • 30
Milan Thummar
  • 261
  • 1
  • 2
  • 11

1 Answers1

0

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

John Blum
  • 7,381
  • 1
  • 20
  • 30
  • I have composite(account number and device sequence number) primary key for respective table. As per the business requirement, user will provide only account number. So, based on that account i want to load all the devices into region from table at once. So, Can i do that using CacheLoader? – Milan Thummar Dec 26 '16 at 09:43
  • @JohnBlum, allow me to pick your brain with regards to predictably loading values. Did you have an idea in mind on how to implement such a thing give the little context available in the cacheloader. – Newbie Jul 31 '17 at 14:38