feat(cache): 新增 JetCache 自动配置

This commit is contained in:
2024-01-14 14:25:35 +08:00
parent e090083ba2
commit 156b02b3d7
6 changed files with 137 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
<?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>top.charles7c.continew</groupId>
<artifactId>continew-starter-cache</artifactId>
<version>${revision}</version>
</parent>
<artifactId>continew-starter-cache-jetcache</artifactId>
<packaging>jar</packaging>
<name>${project.artifactId}</name>
<description>ContiNew Starter 缓存模块 - JetCache</description>
<dependencies>
<!-- JetCache一个基于 Java 的缓存系统封装,提供统一的 API 和注解来简化缓存的使用。提供了比 SpringCache 更加强大的注解,可以原生的支持 TTL、两级缓存、分布式自动刷新还提供了 Cache 接口用于手工缓存操作) -->
<dependency>
<groupId>com.alicp.jetcache</groupId>
<artifactId>jetcache-autoconfigure</artifactId>
</dependency>
<!-- JetCache 注解 -->
<dependency>
<groupId>com.alicp.jetcache</groupId>
<artifactId>jetcache-anno</artifactId>
</dependency>
<!-- JetCache Redisson 适配 -->
<dependency>
<groupId>com.alicp.jetcache</groupId>
<artifactId>jetcache-redisson</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
<!-- 缓存模块 - Redisson -->
<dependency>
<groupId>top.charles7c.continew</groupId>
<artifactId>continew-starter-cache-redisson</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,44 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.charles7c.continew.starter.cache.jetcache.autoconfigure;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;
import top.charles7c.continew.starter.core.handler.GeneralPropertySourceFactory;
/**
* JetCache 自动配置
*
* @author Charles7c
* @since 1.2.0
*/
@Slf4j
@AutoConfiguration
@RequiredArgsConstructor
@Import(com.alicp.jetcache.autoconfigure.JetCacheAutoConfiguration.class)
@PropertySource(value = "classpath:default-cache-jetcache.yml", factory = GeneralPropertySourceFactory.class)
public class JetCacheAutoConfiguration {
@PostConstruct
public void postConstruct() {
log.debug("[ContiNew Starter] - Auto Configuration 'JetCache' completed initialization.");
}
}

View File

@@ -0,0 +1 @@
top.charles7c.continew.starter.cache.jetcache.autoconfigure.JetCacheAutoConfiguration

View File

@@ -0,0 +1,8 @@
--- ### JetCache 配置https://github.com/alibaba/jetcache/blob/master/docs/CN/Config.md
jetcache:
# 统计间隔(默认 0表示不统计
statIntervalMinutes: 15
# jetcache-anno 把 cacheName 作为远程缓存key前缀
# 2.4.3 以前的版本总是把 areaName 加在 cacheName 中,因此 areaName 也出现在 key 前缀中,
# 2.4.4 以后可以配置,为了保持远程 key 兼容默认值为 true但是新项目的话 false 更合理些2.7 默认值已改为 false。
areaInCacheName: false

View File

@@ -18,6 +18,7 @@
<modules>
<module>continew-starter-cache-redisson</module>
<module>continew-starter-cache-springcache</module>
<module>continew-starter-cache-jetcache</module>
</modules>
<dependencies>