0

CacheLoader is not getting called while trying to find an entity using GemfireRepository.

As a solution, I am using Region<K,V> for looking up, which is calling CacheLoader. So wanted to know whether there is any restriction for Spring Data Repository which doesn't allow CacheLoader to be called when entry is not present in the cache.

And, is there any other alternative? Because I have one more scenario where my cache key is combination of id1 & id2 and I want to get all entries based on id1. And if there is no entry present in cache, then it will call CacheLoader to load all entries from Cassandra store.

John Blum
  • 7,381
  • 1
  • 20
  • 30
SUMIT
  • 540
  • 1
  • 4
  • 19
  • Note, loading all entries from Cassandra (or another Data Store) from a `CacheLoader` is quite another thing. Possible, but... – John Blum Mar 16 '20 at 19:55

1 Answers1

1

There are no limitations nor restrictions in SDG when using the SD Repository abstraction (and SDG's Repository extension) that would prevent a CacheLoader from being invoked so long as the CacheLoader was properly registered on the target Region. Once control is handed over to GemFire/Geode to complete the data access operation (CRUD), it is out of SDG's hands.

However, you should know that GemFire/Geode only invokes CacheLoaders on gets (i.e. Region.get(key) operations), never on (OQL) queries. OQL queries are invoked from derived query methods or custom, user-defined query methods using @Query annotated methods declared in the application Repository interface.

NOTE: See Apache Geode CacheLoader Javadoc and User Guide for more details.

For a simple CrudRepository.findById(key) call, the call stack follows from...

  1. SimplyGemfireRepository.findById(key)
  2. GemfireTemplate.get(key)
  3. And then, Region.get(key) (from here).

By way of example, and to illustrate this behavior, I added the o.s.d.g.repository.sample.RepositoryDataAccessOnRegionUsingCacheLoaderIntegrationTests to the SDG test suite as part of DATAGEODE-308. You can provide additional feedback in this JIRA ticket, if necessary.

Cheers!

John Blum
  • 7,381
  • 1
  • 20
  • 30