如何在重新分发中的多个JVM之间同步本地缓存(RLocalCachedMap实例)?

时间:2019-06-18 09:55:42

标签: java caching redis redisson

我正在尝试在Redisson中实现RLocalCachedMap,这很容易。我担心的是如何在多个JVM实例之间同步本地缓存。是通过某种方式自动完成的,还是有一些Redisson代码将缓存同步到多个JVM实例?

我已经包含了文档中提供的缓存选项代码。有一种方法可以跨各种本地缓存实例提供同步策略。但是我的问题仍然是“我们如何告诉一个JVM连接到另一个JVM实例以共享本地缓存?

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);

0 个答案:

没有答案
相关问题