用缓存,你缓存的数据是不是还差点意思?

eg.1
原始代码
public String selectLevyInvoiceNameString_Cache(String merId) {
List<MerchantLevyInvoiceTypeVO> merLevyInvoiceTypeList = CacheUtil.getCache("merLevyInvoiceTypeList" + merId,
90,
() -> merchantLevyInvoiceTypeDAO.selectList(merId));
if (CollectionUtils.isEmpty(merLevyInvoiceTypeList)) {
return "";
}
StringBuilder invoiceType = new StringBuilder();
for (MerchantLevyInvoiceTypeVO item : merLevyInvoiceTypeList) {
if (invoiceType.length() > 0) {
invoiceType.append("/");
}
invoiceType.append(item.invoiceTypeName);
}
return invoiceType.toString();
}
重构后:
public String selectLevyInvoiceNameString_Cache(String merId) {
return CacheUtil.getCache("merLevyInvoiceTypeList" + merId,
90,
() ->
{
List<MerchantLevyInvoiceTypeVO> merLevyInvoiceTypeList = merchantLevyInvoiceTypeDAO.selectList(merId);
if (CollectionUtils.isEmpty(merLevyInvoiceTypeList)) {
return "";
}
StringBuilder invoiceType = new StringBuilder();
for (MerchantLevyInvoiceTypeVO item : merLevyInvoiceTypeList) {
if (invoiceType.length() > 0) {
invoiceType.append("/");
}
invoiceType.append(item.invoiceTypeName);
}
return invoiceType.toString();
});
}
eg.2
原始代码:
Result<LevyFeeRateDto> feeRateDtoResult = LocalCacheUtil.getCache(cacheKey, () -> { Result<LevyFeeRateDto> levyFeeDtoResult = levyMerchantApi.queryLevyFeeRate(levyId); if (!levyFeeDtoResult.isSuccess() || levyFeeDtoResult.getResult() == null) { return null; } return levyFeeDtoResult; }); if (feeRateDtoResult == null || !feeRateDtoResult.isSuccess()) { throw new RetryOrderException("校验费率错误"); } LevyFeeRateDto feeRateDto = feeRateDtoResult.getResult(); if (feeRateDto.getFeeType()...
重构后:
LevyFeeRateDto feeRateDto = LocalCacheUtil.getCache(cacheKey, () -> { Result<LevyFeeRateDto> levyFeeDtoResult = levyMerchantApi.queryLevyFeeRate(levyId); if (!levyFeeDtoResult.isSuccess() || levyFeeDtoResult.getResult() == null) { return null; } return levyFeeDtoResult.getResult(); }); if (feeRateDto == null) { throw new RetryOrderException("校验费率错误"); } if (feeRateDto.getFeeType()...
本文来自公司内部confluence知识库:https://wiki.serviceshare.com/
当看到一些不好的代码时,会发现我还算优秀;当看到优秀的代码时,也才意识到持续学习的重要!--buguge
本文来自博客园,转载请注明原文链接:https://www.cnblogs.com/buguge/p/16795545.html
浙公网安备 33010602011771号