Showing
4 changed files
with
30 additions
and
5 deletions
@@ -44,4 +44,15 @@ public class ResourcesController { | @@ -44,4 +44,15 @@ public class ResourcesController { | ||
44 | request.getClientType()); | 44 | request.getClientType()); |
45 | return new ApiResponse.ApiResponseBuilder().data(data).code(200).message("resources data").build(); | 45 | return new ApiResponse.ApiResponseBuilder().data(data).code(200).message("resources data").build(); |
46 | } | 46 | } |
47 | + | ||
48 | + | ||
49 | + @ApiOperation(name = "ufo.resource.clearCache", desc="资源位清除缓存") | ||
50 | + @RequestMapping(params = "method=ufo.resource.clearCache") | ||
51 | + @ResponseBody | ||
52 | + public ApiResponse getResource(@RequestParam(name = "content_code") String contentCode) { | ||
53 | + | ||
54 | + logger.info("ufo.resource.clearCache content_code={}", contentCode); | ||
55 | + resourcesService.clearCache(contentCode); | ||
56 | + return new ApiResponse.ApiResponseBuilder().data(null).code(200).message("resources data").build(); | ||
57 | + } | ||
47 | } | 58 | } |
@@ -83,6 +83,20 @@ public class ResourcesServiceImpl implements IResourcesService { | @@ -83,6 +83,20 @@ public class ResourcesServiceImpl implements IResourcesService { | ||
83 | resourcesRedisCache.setEx(cacheKey, list, CacheEnum.RESOURCE_GET.getCacheTime()); return list; | 83 | resourcesRedisCache.setEx(cacheKey, list, CacheEnum.RESOURCE_GET.getCacheTime()); return list; |
84 | } | 84 | } |
85 | 85 | ||
86 | + @Override | ||
87 | + public void clearCache(String contentCode) { | ||
88 | + String[] clientType = { "android", "ios" }; | ||
89 | + for (String ct : clientType) { | ||
90 | + try { | ||
91 | + RedisKeyBuilder cacheKey = CacheEnum.RESOURCE_GET.generateKeyLowerCase(contentCode, ct); | ||
92 | + log.info("清除资源位缓存 contentCode={},clientType={}", contentCode, ct); | ||
93 | + resourcesRedisCache.delete(cacheKey); | ||
94 | + } catch (Exception e) { | ||
95 | + log.error("清除资源位缓存错误 contentCode={},clientType={}, err={}", contentCode, ct, e.getMessage()); | ||
96 | + } | ||
97 | + } | ||
98 | + } | ||
99 | + | ||
86 | private void validateRequestForGet(ResourcesRequest request) { | 100 | private void validateRequestForGet(ResourcesRequest request) { |
87 | if (StringUtils.isEmpty(request.getContentCode())) { | 101 | if (StringUtils.isEmpty(request.getContentCode())) { |
88 | log.warn("Content code is empty."); | 102 | log.warn("Content code is empty."); |
@@ -44,12 +44,10 @@ public class TwoPictureResourceParse implements IResourceParse { | @@ -44,12 +44,10 @@ public class TwoPictureResourceParse implements IResourceParse { | ||
44 | 44 | ||
45 | // 处理 data(充分利用原数据库中数据转成的JSONObject,只是遍历之后把URLObject替换成解析之后的数据) | 45 | // 处理 data(充分利用原数据库中数据转成的JSONObject,只是遍历之后把URLObject替换成解析之后的数据) |
46 | JSONObject data = resource.getData().getJSONObject("data"); | 46 | JSONObject data = resource.getData().getJSONObject("data"); |
47 | - | ||
48 | - | ||
49 | - returnJSON.put("template_name",this.TEMPLATE_NAME); | 47 | + returnJSON.put("template_name",TEMPLATE_NAME); |
50 | // 处理 两张图的list | 48 | // 处理 两张图的list |
51 | - for (String index: data.getJSONObject("list").keySet()) { | ||
52 | - makeUrl(data.getJSONObject("list").getJSONObject(index), resource.getClientType()); | 49 | + for (String index: data.keySet()) { |
50 | + makeUrl(data.getJSONObject(index), resource.getClientType()); | ||
53 | } | 51 | } |
54 | returnJSON.put("data",data); | 52 | returnJSON.put("data",data); |
55 | return returnJSON; | 53 | return returnJSON; |
-
Please register or login to post a comment