feat():添加缓存模块封装方法

pull/11/head
YangPeng 2024-09-29 17:06:22 +08:00
parent 93f78cdc3e
commit efd7a46c68
9 changed files with 129 additions and 73 deletions

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.muyu</groupId>
<artifactId>cloud-server</artifactId>
<version>3.6.3</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<description>
cloud-common-cache 缓存基准
</description>
<artifactId>cloud-common- </artifactId>
<properties>
<maven.compiler.source>23</maven.compiler.source>
<maven.compiler.target>23</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- redis 缓存模块-->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-redis</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,33 @@
package com.muyu.common.cache;
import com.muyu.common.redis.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
/**
*
* * @className: CacheAbsBasic
* * @author: Yang 🦅
* * @date: 2024/9/29 16:08
* * @Version: 1.0
* * @description:
*/
public abstract class CacheAbsBasic <K, V> implements CacheBasic<K, V>{
@Autowired
private RedisService redisService;
@Override
public void put(K key, V value) {
redisService.setCacheObject(encode(key), value);
}
@Override
public V get(K key) {
return redisService.getCacheObject(encode(key));
}
@Override
public void remove(K key) {
redisService.deleteObject(encode(key));
}
}

View File

@ -0,0 +1,17 @@
package com.muyu.common.cache;
/**
*
* * @className: CacheBasic
* * @author: Yang 🦅
* * @date: 2024/9/29 16:08
* * @Version: 1.0
* * @description:
*/
public interface CacheBasic<K,V> extends PrimaryKeyBasic<K>{
void put(K key, V value);
V get(K key);
void remove(K key);
}

View File

@ -0,0 +1,36 @@
package com.muyu.common.cache;
/**
*
* * @className: PrimaryKeyBasic
* * @author: Yang 🦅
* * @date: 2024/9/29 16:08
* * @Version: 1.0
* * @description:
*/
public interface PrimaryKeyBasic <K>{
/**
*
* @return
*/
public String keyPre();
/**
*
* @param key
* @return
*/
public default String encode(K key){
return keyPre() + key.toString();
}
/**
*
* @param key
* @return
*/
public default K decode(String key) {
return (K) key.substring(keyPre().length());
}
}

View File

@ -1,38 +0,0 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

View File

@ -1,20 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.muyu</groupId>
<artifactId>cloud-modules-enterprise</artifactId>
<version>3.6.3</version>
</parent>
<artifactId>enterpise-client</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

View File

@ -1,14 +0,0 @@
package com.muyu;
/**
* @Authoryan
* @Packagecom.muyu
* @ProjectDefault (Template) Project
* @name${NAME}
* @Date2024/9/29 09:56
*/
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}

View File

@ -22,7 +22,6 @@
</properties>
<modules>
<module>enterpise-client</module>
<module>enterpise-common</module>
<module>enterpise-remote</module>
<module>enterpise-service</module>

10
pom.xml
View File

@ -44,6 +44,7 @@
<knife4j-openapi3.version>4.1.0</knife4j-openapi3.version>
<xxl-job-core.version>2.4.1</xxl-job-core.version>
<mqtt.version>1.2.5</mqtt.version>
<mybits-plus-business>4.1.65.Final</mybits-plus-business>
</properties>
<!-- 依赖声明 -->
@ -292,6 +293,14 @@
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>${mqtt.version}</version>
</dependency>
<!-- mybits-plus-business 业务依赖 -->
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>${mybits-plus-business}</version>
</dependency>
</dependencies>
</dependencyManagement>
@ -301,6 +310,7 @@
<module>cloud-visual</module>
<module>cloud-modules</module>
<module>cloud-common</module>
<module>cloud-common/cloud-common-cache</module>
</modules>
<packaging>pom</packaging>