快取擴展

擴充說明

使用請求參數作為鍵來快取回傳結果。

擴充點

org.apache.dubbo.cache.CacheFactory

擴充組態

<dubbo:service cache="lru" />
<!-- method level cache -->
<dubbo:service><dubbo:method cache="lru" /></dubbo:service>
<!-- The default value setting, when <dubbo:service> does not configure the cache attribute, use this configuration -->
<dubbo:provider cache="xxx,yyy" />

已知擴充

  • org.apache.dubbo.cache.support.lru.LruCacheFactory
  • org.apache.dubbo.cache.support.threadlocal.ThreadLocalCacheFactory
  • org.apache.dubbo.cache.support.jcache.JCacheFactory

擴充範例

Maven 專案結構

src
 |-main
    |-java
        |-com
            |-xxx
                |-XxxCacheFactory.java (implements the CacheFactory interface)
    |-resources
        |-META-INF
            |-dubbo
                |-org.apache.dubbo.cache.CacheFactory (plain text file, content: xxx=com.xxx.XxxCacheFactory)

XxxCacheFactory.java

package com.xxx;
 
import org.apache.dubbo.cache.CacheFactory;
 
public class XxxCacheFactory implements CacheFactory {
    public Cache getCache(URL url, String name) {
        return new XxxCache(url, name);
    }
}

XxxCache.java

package com.xxx;
 
import org.apache.dubbo.cache.Cache;
 
public class XxxCache implements Cache {
    public Cache(URL url, String name) {
        //...
    }
    public void put(Object key, Object value) {
        //...
    }
    public Object get(Object key) {
        //...
    }
}

META-INF/dubbo/org.apache.dubbo.cache.CacheFactory

xxx=com.xxx.XxxCacheFactory

上次修改時間:2023 年 1 月 2 日:增強英文文件 (#1798) (95a9f4f6c1c)