3

I am trying to implement RLocalCachedMap in Redisson and that is easy. What I am concerned about is how the local cache will be synced between multiple JVM instances. Is it done automatically somehow or there is some Redisson code to sync cache to multiple JVM instances?

I have included the cache options code provided in the documentation. There is a method which provides sync strategy across various local cache instances. But my question remains the same "How are we telling one JVM to connect to another JVM instance to share the local cache?

LocalCachedMapOptions options = LocalCachedMapOptions.defaults()

      // Used to evict local cache entries.
      // Has follow options:
      // LFU - Counts how often an item was requested. Those that are used least often are discarded first.
      // LRU - Discards the least recently used items first
      // SOFT - Uses weak references, entries are removed by GC 
      // WEAK - Uses soft references, entries are removed by GC
      // NONE - No eviction
     .evictionPolicy(EvictionPolicy.NONE)

      // If cache size is 0 then local cache is unbounded.
     .cacheSize(1000)

      // Used to load missed updates during any connection failures to Redis. 
      // Since, local cache updates can't be get in absence of connection to Redis. 
      // Follow reconnection strategies are available:
      // CLEAR - Clear local cache if map instance has been disconnected for a while.
      // LOAD - Store invalidated entry hash in invalidation log for 10 minutes
      //        Cache keys for stored invalidated entry hashes will be removed 
      //        if LocalCachedMap instance has been disconnected less than 10 minutes
      //        or whole cache will be cleaned otherwise.
      // NONE - Default. No reconnection handling
     .reconnectionStrategy(ReconnectionStrategy.NONE)

      // Used to synchronize local cache changes.
      // Follow sync strategies are available:
      // INVALIDATE - Default. Invalidate cache entry across all LocalCachedMap instances on map entry change
      // UPDATE - Update cache entry across all LocalCachedMap instances on map entry change
      // NONE - No synchronizations on map changes
     .syncStrategy(SyncStrategy.INVALIDATE)

      // time to live for each map entry in local cache
     .timeToLive(10000)
      // or
     .timeToLive(10, TimeUnit.SECONDS)

      // max idle time for each map entry in local cache
     .maxIdle(10000)
      // or
     .maxIdle(10, TimeUnit.SECONDS);
Mikhail Zhuikov
  • 1,213
  • 2
  • 9
  • 19
akshit jain
  • 31
  • 1
  • 4
  • NVM, I figured it out. Basically, the local cache is synced automatically across various JVMs when you connect to the same Redisson node(cache server). When you save key-value pair in RLocalCachedMap, it is saved to the cache server automatically and synced to other JVM which connects with it. Now, this doesn't mean you can access those key-value pairs from RMapCache(it 'll throw an exception)but you can access it on the server through Redis-cli. Should be preferred only for data that has a lot of reads because it speeds up reads by 45x as compared to normal implementation. – akshit jain Jun 21 '19 at 06:37
  • Hi Akshit, Did you use free version of Redisson or Redisson Pro? – Sunil Chauraha Jun 11 '20 at 14:56

0 Answers0