购物车缓存 完善1.0
parent
2bfd4882cf
commit
07a3580514
|
@ -1,53 +1,79 @@
|
|||
package com.muyu.product.cache;
|
||||
|
||||
import com.muyu.cache.abs.CacheAbs;
|
||||
import com.muyu.common.cache.HashCache;
|
||||
import com.muyu.common.cache.abs.CacheAbs;
|
||||
import com.muyu.common.core.text.Convert;
|
||||
import com.muyu.product.cache.datasource.ProjectInfoData;
|
||||
import com.muyu.product.domain.ProjectInfo;
|
||||
import com.muyu.product.domain.ProjectSkuInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品缓存 ProjectInfoCache
|
||||
*
|
||||
* @author LeYang
|
||||
* on 2024/3/27
|
||||
* @author yangle
|
||||
* @description: 商品缓存
|
||||
* @Date 2024-3-27 下午 03:30
|
||||
*/
|
||||
@Component
|
||||
public class ProjectInfoCache extends CacheAbs<Long, ProjectInfo> {
|
||||
@Autowired
|
||||
private ProjectInfoData projectInfoData;
|
||||
|
||||
public static void main (String[] args) {
|
||||
Long projectId = 10L;
|
||||
HashCache<Long, Long, ProjectSkuInfo> hashCache = null;
|
||||
List<ProjectSkuInfo> projectSkuInfoList = new ArrayList<>(){{
|
||||
add(new ProjectSkuInfo());
|
||||
add(new ProjectSkuInfo());
|
||||
}};
|
||||
hashCache.put(projectId, projectSkuInfoList, ProjectSkuInfo::getProjectId);
|
||||
Long[] longArr = new Long[]{10L,11L,12L,13L,14L,15L};
|
||||
hashCache.get(projectId, longArr);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private ProjectInfoData projectInfoData;
|
||||
|
||||
/**
|
||||
* key 前缀
|
||||
* @return key 前缀
|
||||
* key前缀
|
||||
*
|
||||
* @return key前缀
|
||||
*/
|
||||
@Override
|
||||
public String keyPre() {
|
||||
public String keyPre () {
|
||||
return "project:info:";
|
||||
}
|
||||
|
||||
/**
|
||||
* 解码
|
||||
*
|
||||
* @param redisKey 数据库键
|
||||
*
|
||||
* @return ID
|
||||
*/
|
||||
@Override
|
||||
public Long decode(String redisKey) {
|
||||
return Convert.toLong(redisKey.replace(keyPre(), ""),0L);
|
||||
public Long decode (String redisKey) {
|
||||
return Convert.toLong(redisKey.replace(keyPre(),""), 0L);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从数据库获取数据
|
||||
*
|
||||
* @param key ID
|
||||
*
|
||||
* @return 缓存对象
|
||||
*/
|
||||
@Override
|
||||
public ProjectInfo getData(Long key) {
|
||||
public ProjectInfo getData (Long key) {
|
||||
return projectInfoData.getData(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认值
|
||||
*/
|
||||
@Override
|
||||
public ProjectInfo defaultValue() {
|
||||
public ProjectInfo defaultValue () {
|
||||
return new ProjectInfo();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue