用缓存,你缓存的数据是不是还差点意思?
2023-09-14 09:06:26 时间
原始代码
public String selectLevyInvoiceNameString_Cache(String merId) { List<TMerchantLevyInvoiceTypeVO> merLevyInvoiceTypeList = CacheUtil.getCache("merLevyInvoiceTypeList" + merId, 90, () -> merchantLevyInvoiceTypeDAO.selectList(merId)); if (CollectionUtil.isEmpty(merLevyInvoiceTypeList)) { return ""; } StringBuilder invoiceType = new StringBuilder(); for (TMerchantLevyInvoiceTypeVO tMerchantLevyInvoiceTypeVO : merLevyInvoiceTypeList) { LevyInvoiceClassVO cache = CacheUtil.getCache("levyInvoiceClass" + tMerchantLevyInvoiceTypeVO.getInvoiceTypeId(), 90, () -> { Result<LevyInvoiceClassVO> voResult = levyInvoiceClassService.getById(tMerchantLevyInvoiceTypeVO.getInvoiceTypeId()); if (voResult.isSuccess() && voResult.getResult() != null) { return voResult.getResult(); } return new LevyInvoiceClassVO(); } ); String invoiceTypeName = cache.getBillClassName(); if (StringUtils.isBlank(invoiceTypeName)) { continue; } if (invoiceType.length() > 0) { invoiceType.append("/"); } invoiceType.append(invoiceTypeName); } return invoiceType.toString(); }
重构后:
public String selectLevyInvoiceNameString_Cache(String merId) { return CacheUtil.getCache("merLevyInvoiceTypeList" + merId, 90, () -> { List<TMerchantLevyInvoiceTypeVO> merLevyInvoiceTypeList = merchantLevyInvoiceTypeDAO.selectList(merId); if (CollectionUtil.isEmpty(merLevyInvoiceTypeList)) { return ""; } StringBuilder invoiceType = new StringBuilder(); for (TMerchantLevyInvoiceTypeVO tMerchantLevyInvoiceTypeVO : merLevyInvoiceTypeList) { LevyInvoiceClassVO cache = CacheUtil.getCache("levyInvoiceClass" + tMerchantLevyInvoiceTypeVO.getInvoiceTypeId(), (int) MINUTES.toSeconds(30), () -> { Result<LevyInvoiceClassVO> voResult = levyInvoiceClassService.getById(tMerchantLevyInvoiceTypeVO.getInvoiceTypeId()); if (voResult.isSuccess() && voResult.getResult() != null) { return voResult.getResult(); } return new LevyInvoiceClassVO(); } ); String invoiceTypeName = cache.getBillClassName(); if (StringUtils.isBlank(invoiceTypeName)) { continue; } if (invoiceType.length() > 0) { invoiceType.append("/"); } invoiceType.append(invoiceTypeName); } return invoiceType.toString(); }); }
相关文章
- Android网络缓存
- 学习yii2.0——数据缓存、片段缓存、页面缓存、http缓存
- Spring4.1新特性——Spring缓存框架增强
- C# Redis缓存过期实现延迟通知实战演练
- webservice 缓存机制
- iOS AFNetworking 数据缓存
- Apache开启Etag缓存禁止,提高访问速度
- HTML5 manifest离线缓存技术
- 第三百节,python操作redis缓存-其他常用操作,用于操作redis里的数据name,不论什么数据类型
- ASP.NET缓存 Cache之数据缓存
- 深入云原生 AI:基于 Alluxio 数据缓存的大规模深度学习训练性能优化
- 应用系统数据缓存设计(转)
- Mybatis 缓存失效的几种情况
- uni-app:数据缓存(hbuilderx 3.6.18)
- Memcache时模拟命名空间及缓存失效问题的解决
- 缓存AsimpleCache -- 解决Android中Sharedpreferences无法存储List数据/ASimpleCache
- EasyCamera海康摄像机向EasyDarwin云平台推送音视频数据的缓存设计
- Glide Picasso Fresco UIL 图片框架 缓存 MD
- django框架进阶-使用缓存-长期维护
- Memcached缓存大数据时对服务器内存、CPU的影响及其对硬件的配置需求
- Memcached缓存大数据时对服务器内存、CPU的影响及其对硬件的配置需求
- Atitit websocket 使用大概总结 使用场景 websocket 实时信息的Web应用却带来了很大的不便,如带有即时通信、实时数据、订阅推送等功能的应 用 实时数据可以用来更新缓存
- ajax如何解决浏览器缓存问题
- 〖Python 数据库开发实战 - Python与Redis交互篇⑪〗- 综合案例 - 新闻管理系统 - 缓存新闻数据至redis
- 学习Spring Boot:(二十一)使用 EhCache 实现数据缓存
- Android-Volley网络通信框架(二次封装数据请求和图片请求(包含处理请求队列和图片缓存))
- 9.3.1 map端连接- DistributedCache分布式缓存小数据集
- 玩转iOS开发 - 数据缓存
- 如何保证缓存与数据库的数据一致性
- ASP.NET_数据缓存理论