0
votes

I am trying to do a poc to use Apache Ignite in our microservices to cache for DB transactions. The following is the Ignite Config code:

IgniteConfiguration igniteConfiguration = new IgniteConfiguration();
igniteConfiguration.setIgniteInstanceName("igniteConfig");

ignite = Ignition.start(igniteConfiguration);

CacheConfiguration<Long, MyClass> myClassCacheConfig = new CacheConfiguration<>("cacheName");
myClassCacheConfig.setIndexedTypes(Long.class, MyClass.class);
myClassCacheConfig.setOnheapCacheEnabled(true);
myClassCacheConfig.setWriteBehindEnabled(false);
myClassCacheConfig.setReadThrough(false);
myClassCacheConfig.setWriteThrough(false);
myClassCacheConfig.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
myClassCacheConfig.setPartitionLossPolicy(PartitionLossPolicy.READ_WRITE_ALL);
myClassCacheConfig.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 1)));

ignite.getOrCreateCache(myClassCacheConfig);

I am using the following dependencies in pom.xml

<!-- https://mvnrepository.com/artifact/org.apache.ignite/ignite-spring -->
<dependency>
    <groupId>org.apache.ignite</groupId>
    <artifactId>ignite-spring</artifactId>
    <version>2.7.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.ignite/ignite-core -->
<dependency>
    <groupId>org.apache.ignite</groupId>
    <artifactId>ignite-core</artifactId>
    <version>2.7.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.ignite/ignite-indexing -->
<dependency>
    <groupId>org.apache.ignite</groupId>
    <artifactId>ignite-indexing</artifactId>
    <version>2.7.6</version>
</dependency>

The following is what I see in the logs:

15:35:13]    __________  ________________ 
[15:35:13]   /  _/ ___/ |/ /  _/_  __/ __/ 
[15:35:13]  _/ // (7 7    // /  / / / _/   
[15:35:13] /___/\___/_/|_/___/ /_/ /___/  
[15:35:13] 
.....
[15:35:16] Ignite node started OK (id=someid, instance name=igniteConfig)
[15:35:16] Topology snapshot [ver=1, locNode=204dbcd4, servers=1, clients=0, state=ACTIVE, CPUs=12, offheap=6.4GB, heap=8.0GB]

The question I have is:

  1. How can I be sure that the data is getting cached?
  2. I am trying to get the size of the cache using the code:

System.out.println("in service cache size is: "+igniteConfigBean.getOrCreateCache("cacheName").size()); I always get 0

So what basic configurations am I missing?

2

2 Answers

0
votes

My guess is that your node on which you calculate cache size does not enter your cluster's topology, instead forming a small empty cluster of its own. Make sure to use client node for that.

Also, make sure to call loadCache() if you want data to be preloaded to your cache from DB. Otherwise, data will only be loaded from DB on request.

https://apacheignite.readme.io/docs/data-loading#ignitecacheloadcache