@Test public void testNull() { invocation.setMethodName("echo1"); invocation.setParameterTypes(new Class<?>[]{String.class}); invocation.setArguments(new Object[]{"arg3"}); 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"); }
@Override public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { if (cacheFactory != null && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.CACHE_KEY))) { Cache cache = cacheFactory.getCache(invoker.getUrl(), invocation); if (cache != null) { String key = StringUtils.toArgumentString(invocation.getArguments()); Object value = cache.get(key); if (value != null) { return new RpcResult(value); } Result result = invoker.invoke(invocation); if (!result.hasException() && result.getValue() != null) { cache.put(key, result.getValue()); } return result; } } return invoker.invoke(invocation); }
CacheFilter implements Filter { @Override public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { if (cacheFactory != null && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.CACHE_KEY))) { Cache cache = cacheFactory.getCache(invoker.getUrl(), invocation); if (cache != null) { String key = StringUtils.toArgumentString(invocation.getArguments()); Object value = cache.get(key); if (value != null) { return new RpcResult(value); } Result result = invoker.invoke(invocation); if (!result.hasException() && result.getValue() != null) { cache.put(key, result.getValue()); } return result; } } return invoker.invoke(invocation); } }
CacheFilter implements Filter { @Override public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { if (cacheFactory != null && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.CACHE_KEY))) { Cache cache = cacheFactory.getCache(invoker.getUrl(), invocation); if (cache != null) { String key = StringUtils.toArgumentString(invocation.getArguments()); Object value = cache.get(key); if (value != null) { return new RpcResult(value); } Result result = invoker.invoke(invocation); if (!result.hasException() && result.getValue() != null) { cache.put(key, result.getValue()); } return result; } } return invoker.invoke(invocation); }  }
CacheFilter implements Filter { @Override public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { if (cacheFactory != null && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.CACHE_KEY))) { Cache cache = cacheFactory.getCache(invoker.getUrl(), invocation); if (cache != null) { String key = StringUtils.toArgumentString(invocation.getArguments()); Object value = cache.get(key); if (value != null) { return new RpcResult(value); } Result result = invoker.invoke(invocation); if (!result.hasException() && result.getValue() != null) { cache.put(key, result.getValue()); } return result; } } return invoker.invoke(invocation); }  void setCacheFactory(CacheFactory cacheFactory); @Override Result invoke(Invoker<?> invoker, Invocation invocation); }
CacheFilter implements Filter { @Override public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { if (cacheFactory != null && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.CACHE_KEY))) { Cache cache = cacheFactory.getCache(invoker.getUrl(), invocation); if (cache != null) { String key = StringUtils.toArgumentString(invocation.getArguments()); Object value = cache.get(key); if (value != null) { return new RpcResult(value); } Result result = invoker.invoke(invocation); if (!result.hasException() && result.getValue() != null) { cache.put(key, result.getValue()); } return result; } } return invoker.invoke(invocation); }  void setCacheFactory(CacheFactory cacheFactory); @Override Result invoke(Invoker<?> invoker, Invocation invocation);  }