购物车缓存 完善1.0

master
rouchen 2024-04-03 08:46:30 +08:00
parent 2bfd4882cf
commit 07a3580514
1 changed files with 40 additions and 14 deletions

View File

@ -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();
}
}