You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2018/04/24 07:35:37 UTC

[GitHub] nikitap492 closed pull request #1099: Reduced amount of the guava cache services code

nikitap492 closed pull request #1099: Reduced amount of the guava cache services code
URL: https://github.com/apache/incubator-skywalking/pull/1099
 
 
   

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/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/CacheUtils.java b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/CacheUtils.java
new file mode 100644
index 000000000..3a5a714d5
--- /dev/null
+++ b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/CacheUtils.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.apm.collector.cache.guava;
+
+
+import com.google.common.cache.Cache;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Optional;
+import java.util.function.Supplier;
+
+import static java.util.Objects.isNull;
+import static java.util.Objects.nonNull;
+
+/**
+ * @author nikitap492
+ */
+public class CacheUtils {
+    private static final Logger logger = LoggerFactory.getLogger(CacheUtils.class);
+
+    public static <K, V> V retrieve(Cache<K, V> cache, K key, Supplier<V> supplier) {
+        V value = null;
+        try {
+            value = cache.get(key, supplier::get);
+        } catch (Throwable e) {
+            logger.error(e.getMessage(), e);
+        }
+
+        if (isNull(value)) {
+            value = supplier.get();
+            if (nonNull(value)) {
+                cache.put(key, value);
+            }
+        }
+
+        return value;
+    }
+
+    public static <K, V> V retrieveOrElse(Cache<K, V> cache, K key, Supplier<V> supplier, V defaultValue) {
+        return Optional.ofNullable(retrieve(cache, key, supplier)).orElse(defaultValue);
+    }
+}
diff --git a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/ApplicationCacheGuavaService.java b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/ApplicationCacheGuavaService.java
index 0de697b79..28ea49d1e 100644
--- a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/ApplicationCacheGuavaService.java
+++ b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/ApplicationCacheGuavaService.java
@@ -20,25 +20,23 @@
 
 import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
+import org.apache.skywalking.apm.collector.cache.guava.CacheUtils;
 import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService;
 import org.apache.skywalking.apm.collector.core.module.ModuleManager;
 import org.apache.skywalking.apm.collector.storage.StorageModule;
 import org.apache.skywalking.apm.collector.storage.dao.cache.IApplicationCacheDAO;
 import org.apache.skywalking.apm.collector.storage.table.register.Application;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import static java.util.Objects.isNull;
-import static java.util.Objects.nonNull;
 
 /**
  * @author peng-yongsheng
  */
 public class ApplicationCacheGuavaService implements ApplicationCacheService {
 
-    private final Logger logger = LoggerFactory.getLogger(ApplicationCacheGuavaService.class);
-
     private final Cache<String, Integer> codeCache = CacheBuilder.newBuilder().initialCapacity(100).maximumSize(1000).build();
+    private final Cache<Integer, Application> applicationCache = CacheBuilder.newBuilder().maximumSize(1000).build();
+    private final Cache<Integer, Integer> addressIdCache = CacheBuilder.newBuilder().maximumSize(1000).build();
 
     private final ModuleManager moduleManager;
     private IApplicationCacheDAO applicationCacheDAO;
@@ -55,57 +53,19 @@ private IApplicationCacheDAO getApplicationCacheDAO() {
     }
 
     @Override public int getApplicationIdByCode(String applicationCode) {
-        int applicationId = 0;
-        try {
-            applicationId = codeCache.get(applicationCode, () -> getApplicationCacheDAO().getApplicationIdByCode(applicationCode));
-        } catch (Throwable e) {
-            logger.error(e.getMessage(), e);
-        }
-
-        if (applicationId == 0) {
-            applicationId = getApplicationCacheDAO().getApplicationIdByCode(applicationCode);
-            if (applicationId != 0) {
-                codeCache.put(applicationCode, applicationId);
-            }
-        }
-        return applicationId;
+        return CacheUtils.retrieveOrElse(codeCache, applicationCode,
+            () -> getApplicationCacheDAO().getApplicationIdByCode(applicationCode), 0);
     }
 
-    private final Cache<Integer, Application> applicationCache = CacheBuilder.newBuilder().maximumSize(1000).build();
-
     @Override public Application getApplicationById(int applicationId) {
-        Application application = null;
-        try {
-            application = applicationCache.get(applicationId, () -> getApplicationCacheDAO().getApplication(applicationId));
-        } catch (Throwable e) {
-            logger.error(e.getMessage(), e);
-        }
-
-        if (isNull(application)) {
-            application = getApplicationCacheDAO().getApplication(applicationId);
-            if (nonNull(application)) {
-                applicationCache.put(applicationId, application);
-            }
-        }
-        return application;
+        return CacheUtils.retrieve(applicationCache, applicationId,
+            () -> getApplicationCacheDAO().getApplication(applicationId));
     }
 
-    private final Cache<Integer, Integer> addressIdCache = CacheBuilder.newBuilder().maximumSize(1000).build();
 
-    @Override public int getApplicationIdByAddressId(int addressId) {
-        int applicationId = 0;
-        try {
-            applicationId = addressIdCache.get(addressId, () -> getApplicationCacheDAO().getApplicationIdByAddressId(addressId));
-        } catch (Throwable e) {
-            logger.error(e.getMessage(), e);
-        }
 
-        if (applicationId == 0) {
-            applicationId = getApplicationCacheDAO().getApplicationIdByAddressId(addressId);
-            if (applicationId != 0) {
-                addressIdCache.put(addressId, applicationId);
-            }
-        }
-        return applicationId;
+    @Override public int getApplicationIdByAddressId(int addressId) {
+        return CacheUtils.retrieveOrElse(addressIdCache, addressId,
+            () -> getApplicationCacheDAO().getApplicationIdByAddressId(addressId), 0);
     }
 }
diff --git a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/InstanceCacheGuavaService.java b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/InstanceCacheGuavaService.java
index 8d87a4a4a..a8984352e 100644
--- a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/InstanceCacheGuavaService.java
+++ b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/InstanceCacheGuavaService.java
@@ -20,13 +20,12 @@
 
 import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
+import org.apache.skywalking.apm.collector.cache.guava.CacheUtils;
 import org.apache.skywalking.apm.collector.cache.service.InstanceCacheService;
 import org.apache.skywalking.apm.collector.core.module.ModuleManager;
 import org.apache.skywalking.apm.collector.core.util.Const;
 import org.apache.skywalking.apm.collector.storage.StorageModule;
 import org.apache.skywalking.apm.collector.storage.dao.cache.IInstanceCacheDAO;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import static java.util.Objects.isNull;
 
@@ -35,8 +34,6 @@
  */
 public class InstanceCacheGuavaService implements InstanceCacheService {
 
-    private final Logger logger = LoggerFactory.getLogger(InstanceCacheGuavaService.class);
-
     private final Cache<Integer, Integer> applicationIdCache = CacheBuilder.newBuilder().initialCapacity(100).maximumSize(5000).build();
 
     private final Cache<String, Integer> agentUUIDCache = CacheBuilder.newBuilder().initialCapacity(100).maximumSize(5000).build();
@@ -58,57 +55,19 @@ private IInstanceCacheDAO getInstanceCacheDAO() {
     }
 
     @Override public int getApplicationId(int instanceId) {
-        int applicationId = 0;
-        try {
-            applicationId = applicationIdCache.get(instanceId, () -> getInstanceCacheDAO().getApplicationId(instanceId));
-        } catch (Throwable e) {
-            logger.error(e.getMessage(), e);
-        }
-
-        if (applicationId == 0) {
-            applicationId = getInstanceCacheDAO().getApplicationId(instanceId);
-            if (applicationId != 0) {
-                applicationIdCache.put(instanceId, applicationId);
-            }
-        }
-        return applicationId;
+        return CacheUtils.retrieveOrElse(applicationIdCache, instanceId,
+            () -> getInstanceCacheDAO().getApplicationId(instanceId), 0);
     }
 
     @Override public int getInstanceIdByAgentUUID(int applicationId, String agentUUID) {
         String key = applicationId + Const.ID_SPLIT + agentUUID;
-
-        int instanceId = 0;
-        try {
-            instanceId = agentUUIDCache.get(key, () -> getInstanceCacheDAO().getInstanceIdByAgentUUID(applicationId, agentUUID));
-        } catch (Throwable e) {
-            logger.error(e.getMessage(), e);
-        }
-
-        if (instanceId == 0) {
-            instanceId = getInstanceCacheDAO().getInstanceIdByAgentUUID(applicationId, agentUUID);
-            if (applicationId != 0) {
-                agentUUIDCache.put(key, instanceId);
-            }
-        }
-        return instanceId;
+        return CacheUtils.retrieveOrElse(agentUUIDCache, key,
+            () -> getInstanceCacheDAO().getInstanceIdByAgentUUID(applicationId, agentUUID), 0);
     }
 
     @Override public int getInstanceIdByAddressId(int applicationId, int addressId) {
         String key = applicationId + Const.ID_SPLIT + addressId;
-
-        int instanceId = 0;
-        try {
-            instanceId = addressIdCache.get(key, () -> getInstanceCacheDAO().getInstanceIdByAddressId(applicationId, addressId));
-        } catch (Throwable e) {
-            logger.error(e.getMessage(), e);
-        }
-
-        if (instanceId == 0) {
-            instanceId = getInstanceCacheDAO().getInstanceIdByAddressId(applicationId, addressId);
-            if (applicationId != 0) {
-                addressIdCache.put(key, instanceId);
-            }
-        }
-        return instanceId;
+        return CacheUtils.retrieveOrElse(addressIdCache, key,
+            () -> getInstanceCacheDAO().getInstanceIdByAddressId(applicationId, addressId), 0);
     }
 }
diff --git a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/NetworkAddressCacheGuavaService.java b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/NetworkAddressCacheGuavaService.java
index 3fe79d718..75a957573 100644
--- a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/NetworkAddressCacheGuavaService.java
+++ b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/NetworkAddressCacheGuavaService.java
@@ -20,14 +20,12 @@
 
 import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
+import org.apache.skywalking.apm.collector.cache.guava.CacheUtils;
 import org.apache.skywalking.apm.collector.cache.service.NetworkAddressCacheService;
 import org.apache.skywalking.apm.collector.core.module.ModuleManager;
-import org.apache.skywalking.apm.collector.core.util.StringUtils;
 import org.apache.skywalking.apm.collector.storage.StorageModule;
 import org.apache.skywalking.apm.collector.storage.dao.cache.INetworkAddressCacheDAO;
 import org.apache.skywalking.apm.collector.storage.table.register.NetworkAddress;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import static java.util.Objects.isNull;
 
@@ -36,9 +34,8 @@
  */
 public class NetworkAddressCacheGuavaService implements NetworkAddressCacheService {
 
-    private final Logger logger = LoggerFactory.getLogger(NetworkAddressCacheGuavaService.class);
-
     private final Cache<String, Integer> addressCache = CacheBuilder.newBuilder().initialCapacity(1000).maximumSize(5000).build();
+    private final Cache<Integer, NetworkAddress> idCache = CacheBuilder.newBuilder().initialCapacity(1000).maximumSize(5000).build();
 
     private final ModuleManager moduleManager;
     private INetworkAddressCacheDAO networkAddressCacheDAO;
@@ -55,39 +52,12 @@ private INetworkAddressCacheDAO getNetworkAddressCacheDAO() {
     }
 
     public int getAddressId(String networkAddress) {
-        int addressId = 0;
-        try {
-            addressId = addressCache.get(networkAddress, () -> getNetworkAddressCacheDAO().getAddressId(networkAddress));
-
-            if (addressId == 0) {
-                addressId = getNetworkAddressCacheDAO().getAddressId(networkAddress);
-                if (addressId != 0) {
-                    addressCache.put(networkAddress, addressId);
-                }
-            }
-        } catch (Throwable e) {
-            logger.error(e.getMessage(), e);
-        }
-
-        return addressId;
+        return CacheUtils.retrieveOrElse(addressCache, networkAddress,
+            () -> getNetworkAddressCacheDAO().getAddressId(networkAddress), 0);
     }
 
-    private final Cache<Integer, NetworkAddress> idCache = CacheBuilder.newBuilder().initialCapacity(1000).maximumSize(5000).build();
 
     public NetworkAddress getAddress(int addressId) {
-        NetworkAddress networkAddress = null;
-        try {
-            networkAddress = idCache.get(addressId, () -> getNetworkAddressCacheDAO().getAddressById(addressId));
-        } catch (Throwable e) {
-            logger.error(e.getMessage(), e);
-        }
-
-        if (isNull(networkAddress)) {
-            networkAddress = getNetworkAddressCacheDAO().getAddressById(addressId);
-            if (StringUtils.isNotEmpty(networkAddress)) {
-                idCache.put(addressId, networkAddress);
-            }
-        }
-        return networkAddress;
+        return CacheUtils.retrieve(idCache, addressId, () -> getNetworkAddressCacheDAO().getAddressById(addressId));
     }
 }
diff --git a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/ServiceIdCacheGuavaService.java b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/ServiceIdCacheGuavaService.java
index 3cae23466..f1639d158 100644
--- a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/ServiceIdCacheGuavaService.java
+++ b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/ServiceIdCacheGuavaService.java
@@ -20,13 +20,12 @@
 
 import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
+import org.apache.skywalking.apm.collector.cache.guava.CacheUtils;
 import org.apache.skywalking.apm.collector.cache.service.ServiceIdCacheService;
 import org.apache.skywalking.apm.collector.core.module.ModuleManager;
 import org.apache.skywalking.apm.collector.core.util.Const;
 import org.apache.skywalking.apm.collector.storage.StorageModule;
 import org.apache.skywalking.apm.collector.storage.dao.cache.IServiceNameCacheDAO;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import static java.util.Objects.isNull;
 
@@ -35,8 +34,6 @@
  */
 public class ServiceIdCacheGuavaService implements ServiceIdCacheService {
 
-    private final Logger logger = LoggerFactory.getLogger(ServiceIdCacheGuavaService.class);
-
     private final Cache<String, Integer> serviceIdCache = CacheBuilder.newBuilder().maximumSize(10000).build();
 
     private final ModuleManager moduleManager;
@@ -54,20 +51,8 @@ private IServiceNameCacheDAO getServiceNameCacheDAO() {
     }
 
     @Override public int get(int applicationId, int srcSpanType, String serviceName) {
-        int serviceId = 0;
         String id = applicationId + Const.ID_SPLIT + srcSpanType + Const.ID_SPLIT + serviceName;
-        try {
-            serviceId = serviceIdCache.get(id, () -> getServiceNameCacheDAO().getServiceId(applicationId, srcSpanType, serviceName));
-        } catch (Throwable e) {
-            logger.error(e.getMessage(), e);
-        }
-
-        if (serviceId == 0) {
-            serviceId = getServiceNameCacheDAO().getServiceId(applicationId, srcSpanType, serviceName);
-            if (serviceId != 0) {
-                serviceIdCache.put(id, serviceId);
-            }
-        }
-        return serviceId;
+        return CacheUtils.retrieveOrElse(serviceIdCache, id,
+            () -> getServiceNameCacheDAO().getServiceId(applicationId, srcSpanType, serviceName), 0);
     }
 }
diff --git a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/ServiceNameCacheGuavaService.java b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/ServiceNameCacheGuavaService.java
index c58781558..e6a1a2d2c 100644
--- a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/ServiceNameCacheGuavaService.java
+++ b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/ServiceNameCacheGuavaService.java
@@ -20,24 +20,20 @@
 
 import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
+import org.apache.skywalking.apm.collector.cache.guava.CacheUtils;
 import org.apache.skywalking.apm.collector.cache.service.ServiceNameCacheService;
 import org.apache.skywalking.apm.collector.core.module.ModuleManager;
 import org.apache.skywalking.apm.collector.storage.StorageModule;
 import org.apache.skywalking.apm.collector.storage.dao.cache.IServiceNameCacheDAO;
 import org.apache.skywalking.apm.collector.storage.table.register.ServiceName;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import static java.util.Objects.isNull;
-import static java.util.Objects.nonNull;
 
 /**
  * @author peng-yongsheng
  */
 public class ServiceNameCacheGuavaService implements ServiceNameCacheService {
 
-    private final Logger logger = LoggerFactory.getLogger(ServiceNameCacheGuavaService.class);
-
     private final Cache<Integer, ServiceName> serviceCache = CacheBuilder.newBuilder().maximumSize(10000).build();
 
     private final ModuleManager moduleManager;
@@ -55,20 +51,6 @@ private IServiceNameCacheDAO getServiceNameCacheDAO() {
     }
 
     public ServiceName get(int serviceId) {
-        ServiceName serviceName = null;
-        try {
-            serviceName = serviceCache.get(serviceId, () -> getServiceNameCacheDAO().get(serviceId));
-        } catch (Throwable e) {
-            logger.error(e.getMessage(), e);
-        }
-
-        if (isNull(serviceName)) {
-            serviceName = getServiceNameCacheDAO().get(serviceId);
-            if (nonNull(serviceName)) {
-                serviceCache.put(serviceId, serviceName);
-            }
-        }
-
-        return serviceName;
+        return CacheUtils.retrieve(serviceCache, serviceId, () -> getServiceNameCacheDAO().get(serviceId));
     }
 }
diff --git a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/test/java/org/apache/skywalking/apm/collector/cache/guava/CacheUtilsUnitTest.java b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/test/java/org/apache/skywalking/apm/collector/cache/guava/CacheUtilsUnitTest.java
new file mode 100644
index 000000000..b4337595f
--- /dev/null
+++ b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/test/java/org/apache/skywalking/apm/collector/cache/guava/CacheUtilsUnitTest.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.apm.collector.cache.guava;
+
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+
+/**
+ * @author nikitap492
+ */
+public class CacheUtilsUnitTest {
+
+    private Cache<Integer, String> testCache = CacheBuilder.newBuilder().maximumSize(10).build();
+    
+    private Cache<String, Integer> stringCache = CacheBuilder.newBuilder().maximumSize(10).build();
+
+    @Before
+    public void init() {
+        testCache.put(5, "five");
+    }
+
+    @Test
+    public void retrieve() {
+        String value = CacheUtils.retrieve(testCache, 5, () -> null);
+        assertEquals(value, "five");
+
+        value = CacheUtils.retrieve(testCache, 10, () -> "ten");
+        assertEquals(value, "ten");
+        assertEquals(value, testCache.getIfPresent(10)); //put into the cache
+
+    }
+
+    @Test
+    public void retrieveOrElse() {
+        String value = CacheUtils.retrieveOrElse(testCache, 12, () -> null, "twelve");
+        assertEquals(value, "twelve");
+    }
+    
+    @Test
+    public void retrieveWhenFirstTimeNotFound() {
+        ApplicationDAO dao = new ApplicationDAO();
+
+        Integer value = CacheUtils.retrieveOrElse(stringCache, "test", dao::getIdByCode, 0);
+        assertEquals(value.intValue(), 0);
+
+        dao.id = 10;
+
+        value = CacheUtils.retrieveOrElse(stringCache, "test", dao::getIdByCode, 0);
+        assertEquals(value.intValue(), 10);
+    }
+
+    class ApplicationDAO {
+
+        private int id = 0;
+
+        int getIdByCode() {
+            return id;
+        }
+    }
+}
diff --git a/skywalking-ui b/skywalking-ui
index a42f1b27d..922c012ef 160000
--- a/skywalking-ui
+++ b/skywalking-ui
@@ -1 +1 @@
-Subproject commit a42f1b27d5c8cbde86945767830f71fe41c532df
+Subproject commit 922c012efd0c385e3c502d06d2730c73452f779d


 

----------------------------------------------------------------
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