You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2018/09/21 02:35:55 UTC

[GitHub] diecui1202 closed pull request #2480: Support for caching null values

diecui1202 closed pull request #2480:  Support for caching null values
URL: https://github.com/apache/incubator-dubbo/pull/2480
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 f7e362ba58..62a739d186 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
@@ -16,6 +16,8 @@
  */
 package org.apache.dubbo.cache.filter;
 
+import java.io.Serializable;
+
 import org.apache.dubbo.cache.Cache;
 import org.apache.dubbo.cache.CacheFactory;
 import org.apache.dubbo.common.Constants;
@@ -49,16 +51,34 @@ public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcExcept
                 String key = StringUtils.toArgumentString(invocation.getArguments());
                 Object value = cache.get(key);
                 if (value != null) {
-                    return new RpcResult(value);
+                    if (value instanceof ValueWrapper) {
+                        return new RpcResult(((ValueWrapper)value).get());
+                    } else {
+                        return new RpcResult(value);
+                    }
                 }
                 Result result = invoker.invoke(invocation);
-                if (!result.hasException() && result.getValue() != null) {
-                    cache.put(key, result.getValue());
+                if (!result.hasException()) {
+                    cache.put(key, new ValueWrapper(result.getValue()));
                 }
                 return result;
             }
         }
         return invoker.invoke(invocation);
     }
+    
+    static class ValueWrapper implements Serializable{
+
+        private static final long serialVersionUID = -1777337318019193256L;
 
+        private final Object value;
+
+        public ValueWrapper(Object value){
+            this.value = value;
+        }
+
+        public Object get() {
+            return this.value;
+        }
+    }
 }
diff --git a/dubbo-filter/dubbo-filter-cache/src/test/java/org/apache/dubbo/cache/filter/CacheFilterTest.java b/dubbo-filter/dubbo-filter-cache/src/test/java/org/apache/dubbo/cache/filter/CacheFilterTest.java
index c51bce79b9..7d571dd644 100644
--- a/dubbo-filter/dubbo-filter-cache/src/test/java/org/apache/dubbo/cache/filter/CacheFilterTest.java
+++ b/dubbo-filter/dubbo-filter-cache/src/test/java/org/apache/dubbo/cache/filter/CacheFilterTest.java
@@ -134,7 +134,7 @@ public void testNull() {
         cacheFilter.invoke(invoker4, invocation);
         RpcResult rpcResult1 = (RpcResult) cacheFilter.invoke(invoker1, invocation);
         RpcResult rpcResult2 = (RpcResult) cacheFilter.invoke(invoker2, invocation);
-        Assert.assertEquals(rpcResult1.getValue(), "value1");
-        Assert.assertEquals(rpcResult2.getValue(), "value1");
+        Assert.assertEquals(rpcResult1.getValue(), null);
+        Assert.assertEquals(rpcResult2.getValue(), null);
     }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org