Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/javafamilyclub/javafamily-cache
JavaFamily Cache Library
https://github.com/javafamilyclub/javafamily-cache
Last synced: about 1 month ago
JSON representation
JavaFamily Cache Library
- Host: GitHub
- URL: https://github.com/javafamilyclub/javafamily-cache
- Owner: JavaFamilyClub
- License: apache-2.0
- Created: 2020-05-10T03:08:38.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-08-29T14:38:49.000Z (over 2 years ago)
- Last Synced: 2023-07-28T00:16:08.634Z (over 1 year ago)
- Size: 182 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# javafamily-cache
> JavaFamily 缓存组件 SpringBoot Starter
[![Build](https://github.com/JavaFamilyClub/javafamily-cache/actions/workflows/maven-build.yml/badge.svg)](https://github.com/JavaFamilyClub/javafamily-cache/actions/workflows/maven-build.yml)
[![MavenPublishSnapshot](https://github.com/JavaFamilyClub/javafamily-cache/actions/workflows/maven-publish-snapshot.yml/badge.svg)](https://github.com/JavaFamilyClub/javafamily-cache/actions/workflows/maven-publish-snapshot.yml)
[![MavenPublishRelease](https://github.com/JavaFamilyClub/javafamily-cache/actions/workflows/maven-publish-release.yml/badge.svg)](https://github.com/JavaFamilyClub/javafamily-cache/actions/workflows/maven-publish-release.yml)## 1. 引入依赖
* Maven Central Release
``` xml
club.javafamily
javafamily-cache
2.3.2-beta.2```
* Maven Central Snapshot
``` xml
maven-central
https://oss.sonatype.org/content/repositories/snapshots
false
never
true
always
club.javafamily
javafamily-cache
2.3.2-SNAPSHOT
```## 2. 配置
> 缓存组件底层目前提供 `caffeine` 及 `redis` 两种实现方式, 默认为 `caffeine` 实现, 可支持配置包括:
| 属性 | 类型 | 描述 | 默认值 |
| -- | - | ----- | -- |
| javafamily.cache.type | CacheType | Cache type. support caffeine/redis | caffeine |
| javafamily.cache.cache-null-values | java.lang.Boolean | Allow caching null values. | true |
| javafamily.cache.key-prefix | java.lang.String | Key prefix. | |
| javafamily.cache.time-to-live | java.time.Duration | Entry expiration. By default the entries never expire. | |
| javafamily.cache.use-key-prefix | java.lang.Boolean | Whether to use the key prefix when writing to cache. | true |
| javafamily.cache.caffeine.spec | java.lang.String | The spec to use to create caches. | |
| javafamily.cache.caffeine.initSize | java.lang.Integer | 初始化容量. | 100 |
| javafamily.cache.caffeine.maxSize | java.lang.Long | 最大容量. | 2000 |
| javafamily.cache.caffeine.weakKeys | java.lang.Boolean | key 是否启用软引用. | false |
| javafamily.cache.caffeine.weakValues | java.lang.Boolean | value 是否启用软引用. | false |
| javafamily.cache.caffeine.softValues | java.lang.Boolean | value 是否启用软引用. | false |
| javafamily.cache.caffeine.recordStats | java.lang.Boolean | 是否启用状态记录. | false |## 3. 使用
> 通过注入 `CacheOperator` 对象进行缓存操作.
```java
@SpringBootTest
class CacheSimpleDemoApplicationTests {@Autowired
private CacheOperator cacheOperator;@Test
void testGetSet() {
cacheOperator.setValue("key1", "v1");String v1 = cacheOperator.getValue("key1");
Assertions.assertEquals(v1, "v1");
}
}
```
## 4. 示例代码* `Caffeine`: [Caffeine 示例代码](./examples/cache-simple-demo)
* `Redis`: [Redis 示例代码](./examples/cache-redis-demo)