-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Zhengjiaao
committed
Apr 11, 2024
1 parent
70e2de5
commit bb401ef
Showing
5 changed files
with
154 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
starter-cache/src/main/java/com/zja/model/UserRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.zja.model; | ||
|
||
import io.swagger.annotations.ApiModel; | ||
import io.swagger.annotations.ApiModelProperty; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.io.Serializable; | ||
import java.util.Date; | ||
|
||
/** | ||
* @author [email protected] | ||
* @data 2019/6/27 16:35 | ||
*/ | ||
@ApiModel(value = "用户信息") | ||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@EqualsAndHashCode(callSuper = false) | ||
public class UserRequest implements Serializable { | ||
@ApiModelProperty(value = "用户id") | ||
private String id; | ||
@ApiModelProperty(value = "用户名") | ||
private String name; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
starter-cache/src/test/java/com/zja/service/CacheDataServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.zja.service; | ||
|
||
import com.zja.model.UserRequest; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author: zhengja | ||
* @since: 2024/04/11 10:44 | ||
*/ | ||
@SpringBootTest | ||
public class CacheDataServiceTest { | ||
|
||
@Autowired | ||
CacheDataService service; | ||
|
||
// 简单 保存缓存、更新缓存、查找缓存、删除缓存 | ||
@Test | ||
public void test_1() { | ||
service.save(1); // 进入方法,保存数据,并缓存数据 | ||
int i = service.find(1); // 不进入方法,直接从缓存中取数据 | ||
System.out.println(i); | ||
|
||
service.update(1); // 进入方法,更新数据,并更新缓存数据 | ||
int i2 = service.find(1); // 不进入方法,直接从缓存中取数据 | ||
System.out.println(i2); | ||
|
||
service.delete(1); // 进入方法,删除数据,并删除缓存 | ||
service.delectAll(); // 进入方法,删除全部数据,并删除全部缓存 | ||
} | ||
|
||
// 对象 | ||
@Test | ||
public void test_2() { | ||
service.findUserDTO(new UserRequest("1", "李四")); // 进入方法,返回数据,并进行缓存数据 | ||
service.findUserDTO(new UserRequest("1", "李四")); // 不进入方法,直接从缓存中取数据 | ||
|
||
service.findUserDTO(new UserRequest("2", "李四")); // 进入方法,返回数据,并进行缓存数据 | ||
} | ||
|
||
// list | ||
@Test | ||
public void test_3() { | ||
List<UserRequest> requestList = new ArrayList<>(); | ||
requestList.add(new UserRequest("1", "李四")); | ||
service.findUserDTOList(requestList); // 进入方法,返回数据,并进行缓存数据 | ||
service.findUserDTOList(requestList); // 不进入方法,直接从缓存中取数据 | ||
|
||
List<UserRequest> requestList2 = new ArrayList<>(); | ||
requestList2.add(new UserRequest("1", "李四")); | ||
requestList2.add(new UserRequest("2", "李四")); | ||
service.findUserDTOList(requestList2); // 进入方法,返回数据,并进行缓存数据 | ||
} | ||
|
||
// map | ||
@Test | ||
public void test_4() { | ||
Map<String, Object> objectMap = new HashMap<>(); | ||
objectMap.put("1", "李四"); | ||
|
||
service.findUserDTOList(objectMap);// 进入方法,返回数据,并进行缓存数据 | ||
service.findUserDTOList(objectMap);// 不进入方法,直接从缓存中取数据 | ||
|
||
Map<String, Object> objectMap2 = new HashMap<>(); | ||
objectMap2.put("2", "李四"); | ||
service.findUserDTOList(objectMap2);// 进入方法,返回数据,并进行缓存数据 | ||
} | ||
|
||
} |