初始化
This commit is contained in:
42
easyflow-commons/easyflow-common-cache/pom.xml
Normal file
42
easyflow-commons/easyflow-common-cache/pom.xml
Normal file
@@ -0,0 +1,42 @@
|
||||
<?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>tech.easyflow</groupId>
|
||||
<artifactId>easyflow-commons</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<name>easyflow-common-cache</name>
|
||||
<artifactId>easyflow-common-cache</artifactId>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<version>5.2.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alicp.jetcache</groupId>
|
||||
<artifactId>jetcache-starter-redis</artifactId>
|
||||
<version>2.7.7</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
42
easyflow-commons/easyflow-common-cache/src/main/java/tech/easyflow/common/cache/CacheConfig.java
vendored
Normal file
42
easyflow-commons/easyflow-common-cache/src/main/java/tech/easyflow/common/cache/CacheConfig.java
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
package tech.easyflow.common.cache;
|
||||
|
||||
import com.alicp.jetcache.Cache;
|
||||
import com.alicp.jetcache.CacheManager;
|
||||
import com.alicp.jetcache.anno.CacheType;
|
||||
import com.alicp.jetcache.template.QuickConfig;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class CacheConfig {
|
||||
|
||||
@Autowired
|
||||
private CacheManager cacheManager;
|
||||
@Value("${jetcache.cacheType}")
|
||||
private String cacheType;
|
||||
|
||||
private Cache<String, Object> defaultCache;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
CacheType type = CacheType.LOCAL;
|
||||
if ("remote".equals(cacheType)) {
|
||||
type = CacheType.REMOTE;
|
||||
}
|
||||
if ("both".equals(cacheType)) {
|
||||
type = CacheType.BOTH;
|
||||
}
|
||||
QuickConfig quickConfig = QuickConfig.newBuilder("")
|
||||
.cacheType(type)
|
||||
.build();
|
||||
defaultCache = cacheManager.getOrCreateCache(quickConfig);
|
||||
}
|
||||
|
||||
@Bean("defaultCache")
|
||||
public Cache<String, Object> getDefaultCache() {
|
||||
return defaultCache;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user