Cache Extension

Cache Extension

Extension Description

Use request parameters as keys to cache return results.

Extension Interface

org.apache.dubbo.cache.CacheFactory

Extension Configuration

  1. <dubbo:service cache="lru" />
  2. <!-- Method-level caching -->
  3. <dubbo:service><dubbo:method cache="lru" /></dubbo:service>
  4. <!-- Default value setting, used when <dubbo:service> does not configure the cache property -->
  5. <dubbo:provider cache="xxx,yyy" />

Known Extensions

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

Extension Examples

Maven project structure:

  1. src
  2. |-main
  3. |-java
  4. |-com
  5. |-xxx
  6. |-XxxCacheFactory.java (implements CacheFactory interface)
  7. |-resources
  8. |-META-INF
  9. |-dubbo
  10. |-org.apache.dubbo.cache.CacheFactory (plain text file, content: xxx=com.xxx.XxxCacheFactory)

XxxCacheFactory.java:

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

XxxCache.java:

  1. package com.xxx;
  2. import org.apache.dubbo.cache.Cache;
  3. public class XxxCache implements Cache {
  4. public Cache(URL url, String name) {
  5. // ...
  6. }
  7. public void put(Object key, Object value) {
  8. // ...
  9. }
  10. public Object get(Object key) {
  11. // ...
  12. }
  13. }

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

  1. xxx=com.xxx.XxxCacheFactory

Feedback

Was this page helpful?

Yes No

Last modified September 30, 2024: Update & Translate Overview Docs (#3040) (d37ebceaea7)