diff --git a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/Cache.java b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/Cache.java
index 4ba84eb31e6..fb2a329fc15 100644
--- a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/Cache.java
+++ b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/Cache.java
@@ -17,12 +17,27 @@
package org.apache.dubbo.cache;
/**
- * Cache
+ * Cache interface to support storing and retrieval of value against a lookup key. It has two operation get and put.
+ *
put-Storing value against a key.
+ *
get-Retrival of object.
+ * @see org.apache.dubbo.cache.support.lru.LruCache
+ * @see org.apache.dubbo.cache.support.jcache.JCache
+ * @see org.apache.dubbo.cache.support.expiring.ExpiringCache
+ * @see org.apache.dubbo.cache.support.threadlocal.ThreadLocalCache
*/
public interface Cache {
-
+ /**
+ * API to store value against a key
+ * @param key Unique identifier for the object being store.
+ * @param value Value getting store
+ */
void put(Object key, Object value);
+ /**
+ * API to return stored value using a key.
+ * @param key Unique identifier for cache lookup
+ * @return Return stored object against key
+ */
Object get(Object key);
}
diff --git a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/CacheFactory.java b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/CacheFactory.java
index 2fabd94a5f3..77256bb5ee5 100644
--- a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/CacheFactory.java
+++ b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/CacheFactory.java
@@ -22,11 +22,21 @@
import org.apache.dubbo.rpc.Invocation;
/**
- * CacheFactory
+ * Interface needs to be implemented by all the cache store provider.Along with implementing CacheFactory interface
+ * entry needs to be added in org.apache.dubbo.cache.CacheFactory file in a classpath META-INF sub directories.
+ *
+ * @see Cache
*/
@SPI("lru")
public interface CacheFactory {
+ /**
+ * CacheFactory implementation class needs to implement this return underlying cache instance for method against
+ * url and invocation.
+ * @param url
+ * @param invocation
+ * @return Instance of Cache containing cached value against method url and invocation.
+ */
@Adaptive("cache")
Cache getCache(URL url, Invocation invocation);
diff --git a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/filter/CacheFilter.java b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/filter/CacheFilter.java
index ee6282659aa..4de9f5a170c 100644
--- a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/filter/CacheFilter.java
+++ b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/filter/CacheFilter.java
@@ -32,17 +32,60 @@
import java.io.Serializable;
/**
- * CacheFilter
+ * CacheFilter is a core component of dubbo.Enabling cache key of service,method,consumer or provider dubbo will cache method return value.
+ * Along with cache key we need to configure cache type. Dubbo default implemented cache types are
+ *
lur
+ *
threadlocal
+ *
jcache
+ *
expiring
+ *
+ *
+ * e.g. 1)<dubbo:service cache="lru" />
+ * 2)<dubbo:service /> <dubbo:method name="method2" cache="threadlocal" /> <dubbo:service/>
+ * 3)<dubbo:provider cache="expiring" />
+ * 4)<dubbo:consumer cache="jcache" />
+ *
+ *If cache type is defined in method level then method level type will get precedence. According to above provided
+ *example, if service has two method, method1 and method2, method2 will have cache type as threadlocal where others will
+ *be backed by lru
+ *
+ *
+ * @see org.apache.dubbo.rpc.Filter
+ * @see org.apache.dubbo.cache.support.lru.LruCacheFactory
+ * @see org.apache.dubbo.cache.support.lru.LruCache
+ * @see org.apache.dubbo.cache.support.jcache.JCacheFactory
+ * @see org.apache.dubbo.cache.support.jcache.JCache
+ * @see org.apache.dubbo.cache.support.threadlocal.ThreadLocalCacheFactory
+ * @see org.apache.dubbo.cache.support.threadlocal.ThreadLocalCache
+ * @see org.apache.dubbo.cache.support.expiring.ExpiringCacheFactory
+ * @see org.apache.dubbo.cache.support.expiring.ExpiringCache
+ *
*/
@Activate(group = {Constants.CONSUMER, Constants.PROVIDER}, value = Constants.CACHE_KEY)
public class CacheFilter implements Filter {
private CacheFactory cacheFactory;
+ /**
+ * Dubbo will populate and set the cache factory instance based on service/method/consumer/provider configured
+ * cache attribute value. Dubbo will search for the class name implementing configured cache in file org.apache.dubbo.cache.CacheFactory
+ * under META-INF sub folders.
+ *
+ * @param cacheFactory instance of CacheFactory based on cache type
+ */
public void setCacheFactory(CacheFactory cacheFactory) {
this.cacheFactory = cacheFactory;
}
+ /**
+ * If cache is configured, dubbo will invoke method on each method call. If cache value is returned by cache store
+ * then it will return otherwise call the remote method and return value. If remote method's return valeu has error
+ * then it will not cache the value.
+ * @param invoker service
+ * @param invocation invocation.
+ * @return Cache returned value if found by the underlying cache store. If cache miss it will call target method.
+ * @throws RpcException
+ */
@Override
public Result invoke(Invoker> invoker, Invocation invocation) throws RpcException {
if (cacheFactory != null && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.CACHE_KEY))) {
@@ -66,7 +109,10 @@ public Result invoke(Invoker> invoker, Invocation invocation) throws RpcExcept
}
return invoker.invoke(invocation);
}
-
+
+ /**
+ * Cache value wrapper.
+ */
static class ValueWrapper implements Serializable{
private static final long serialVersionUID = -1777337318019193256L;
diff --git a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/AbstractCacheFactory.java b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/AbstractCacheFactory.java
index ad95e770e0d..2522ce775a8 100644
--- a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/AbstractCacheFactory.java
+++ b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/AbstractCacheFactory.java
@@ -26,12 +26,29 @@
import java.util.concurrent.ConcurrentMap;
/**
- * AbstractCacheFactory
+ * AbstractCacheFactory is a default implementation of {@link CacheFactory}. It abstract out the key formation from URL along with
+ * invocation method. It initially check if the value for key already present in own local in-memory store then it won't check underlying storage cache {@link Cache}.
+ * Internally it used {@link ConcurrentHashMap} to store do level-1 caching.
+ *
+ * @see CacheFactory
+ * @see org.apache.dubbo.cache.support.jcache.JCacheFactory
+ * @see org.apache.dubbo.cache.support.lru.LruCacheFactory
+ * @see org.apache.dubbo.cache.support.threadlocal.ThreadLocalCacheFactory
+ * @see org.apache.dubbo.cache.support.expiring.ExpiringCacheFactory
*/
public abstract class AbstractCacheFactory implements CacheFactory {
+ /**
+ * This is used to store factory level-1 cached data.
+ */
private final ConcurrentMap caches = new ConcurrentHashMap();
+ /**
+ * Takes URL and invocation instance and return cache instance for a given url.
+ * @param url url of the method
+ * @param invocation invocation context.
+ * @return Instance of cache store used as storage for caching return values.
+ */
@Override
public Cache getCache(URL url, Invocation invocation) {
url = url.addParameter(Constants.METHOD_KEY, invocation.getMethodName());
@@ -44,6 +61,11 @@ public Cache getCache(URL url, Invocation invocation) {
return cache;
}
+ /**
+ * Takes url as an method argument and return new instance of cache store implemented by AbstractCacheFactory subclass.
+ * @param url url of the method
+ * @return Create and return new instance of cache store used as storage for caching return values.
+ */
protected abstract Cache createCache(URL url);
}
diff --git a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringCache.java b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringCache.java
index 9fd61f59504..9295718dfc7 100644
--- a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringCache.java
+++ b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringCache.java
@@ -24,6 +24,22 @@
/**
* ExpiringCache - With the characteristic of expiration time.
*/
+
+/**
+ * This class store the cache value with the characteristic of expiration time. If a service,method,consumer or provided is configured with key cache
+ * with value expiring, dubbo initialize the instance of this class using {@link ExpiringCacheFactory} to store method's returns value
+ * to server from store without making method call.
+ *