将 IMCache 与 Web 应用程序集成

Integrate IMCache with web application

我正在尝试将 IMCache offheap 与 Web 应用程序集成。当我 运行 给出的示例(添加了下面的代码)时,JVM 在成功执行代码后永远不会退出。

    OffHeapByteBufferStore bufferStore = new OffHeapByteBufferStore(8388608 ,10, 1);
    final Cache<String,String> offHeapCache = CacheBuilder.offHeapCache().storage(bufferStore)
      .cacheLoader(new CacheLoader<String, String>() {
        public String load(String key) {
            return cacheDao.load(key);
        }
    }).evictionListener(new EvictionListener<String, String>() {
        public void onEviction(String key, String value) {
            cacheDao.store(key, value);
        }
    }).build();

    for(int i = 0; i < 1000; i++){
        offHeapCache.put("key-" + i, "value - " + i);
    }  
    System.out.println(offHeapCache.get("key-" + 100));

如何将堆外缓存与我的 Web 应用程序集成?

Imcache 使用执行程序服务来清理字节缓冲区。这实际上与垃圾收集几乎相同。

您可以在 https://github.com/Cetsoft/imcache/blob/master/imcache-offheap/src/main/java/com/cetsoft/imcache/cache/offheap/OffHeapCache.java#L145

查看源代码