From 1496edd7e9400d4d93b28f3765470eac50ecf8a4 Mon Sep 17 00:00:00 2001 From: karthik-tarento Date: Fri, 10 Jun 2022 13:07:41 +0530 Subject: [PATCH] Fix for redis cache issue --- .../searchby/service/SearchByService.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/sunbird/searchby/service/SearchByService.java b/src/main/java/org/sunbird/searchby/service/SearchByService.java index 327e2af12..0c3ca6bc9 100644 --- a/src/main/java/org/sunbird/searchby/service/SearchByService.java +++ b/src/main/java/org/sunbird/searchby/service/SearchByService.java @@ -13,6 +13,7 @@ import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; +import org.springframework.util.ObjectUtils; import org.sunbird.cache.RedisCacheMgr; import org.sunbird.common.model.FracApiResponse; import org.sunbird.common.service.OutboundRequestHandlerServiceImpl; @@ -69,18 +70,21 @@ public FracApiResponse listDesignations(String userToken) { response.setStatusInfo(new FracStatusInfo()); response.getStatusInfo().setStatusCode(HttpStatus.OK.value()); - List> positionList = (List>) redisCacheMgr + Map>> positionList = (Map>>) redisCacheMgr .getCache(Constants.POSITIONS_CACHE_NAME); - if (CollectionUtils.isEmpty(positionList)) { + if (ObjectUtils.isEmpty(positionList) + || CollectionUtils.isEmpty(positionList.get(Constants.POSITIONS_CACHE_NAME))) { logger.info("Initializing / Refreshing the Cache value for key : " + Constants.POSITIONS_CACHE_NAME); try { positionList = updateDesignationDetails(userToken); - response.setResponseData(positionList); + response.setResponseData(positionList.get(Constants.POSITIONS_CACHE_NAME)); } catch (Exception e) { logger.error(e); response.getStatusInfo().setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR.value()); response.getStatusInfo().setErrorMessage(e.getMessage()); } + } else { + response.setResponseData(positionList.get(Constants.POSITIONS_CACHE_NAME)); } return response; @@ -318,7 +322,7 @@ private Map updateProviderDetails(String authUserToken) th return providerMap; } - private List> updateDesignationDetails(String authUserToken) throws Exception { + private Map>> updateDesignationDetails(String authUserToken) throws Exception { Map headers = new HashMap<>(); HashMap reqBody = new HashMap<>(); headers = new HashMap<>(); @@ -366,8 +370,10 @@ private List> updateDesignationDetails(String authUserToken) } throw err; } - redisCacheMgr.putCache(Constants.POSITIONS_CACHE_NAME, positionList); - return positionList; + Map>> positionMap = new HashMap>>(); + positionMap.put(Constants.POSITIONS_CACHE_NAME, positionList); + redisCacheMgr.putCache(Constants.POSITIONS_CACHE_NAME, positionMap); + return positionMap; } private List> getMasterPositionList(List positionNameList) throws Exception {