Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
howaric committed Mar 9, 2022
1 parent dd335bc commit 421746f
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,29 @@

This project aims to enhance springboot cache without code invasion in high concurrency scenarios.

## Roadmap
## Features

- [x] Delayed re-eviction of cache by @CacheEvict
- [ ] Retry eviction of cache when failed to delete cache
- [ ] Random cache TTL in a specific range
- [X] Support to evict cache again in a delay time by @CacheEvict
- [ ] Provide retry mechanism when eviction of cache failed
- [ ] Random cache TTL in a specific range

## User Guide
## Usage

Add dependency as below, latest version: [![Github release](https://img.shields.io/github/v/release/howaric/spring-enhanced-cache.svg)](https://GitHub.com/howaric/spring-enhanced-cache/releases)
### Add dependency

Latest version: [![Github release](https://img.shields.io/github/v/release/howaric/spring-enhanced-cache.svg)](https://GitHub.com/howaric/spring-enhanced-cache/releases)

```xml
<dependency>
<groupId>cn.howaric.cache</groupId>
<artifactId>spring-boot-starter-cache-enhancer</artifactId>
<version>0.0.1</version>
<version>${latest.version}</version>
</dependency>
```
>spring-boot-starter-cache won't be needed when this dependency is added in your project.

Add a cache implementation such as redis:
> spring-boot-starter-cache won't be needed when this dependency is added in your project.
Add a cache implementation, here uses redis as an example.

```xml
<dependency>
Expand All @@ -36,9 +39,11 @@ Add a cache implementation such as redis:
</dependency>
```

You can define your own CacheManager, if not, a default CacheManager will be created. By the way, this default CacheManager is not created by the enhancer but spring cache.
You can define your own CacheManager, or use the default CacheManager which created by spring cache AutoConfiguration.

### Setup configuration

The enhancer will create an EnhancedCacheManager and inject to spring container, the EnhancedCacheManager's name is defined in `cn.howaric.cache.enhancer.EnhancedCacheManager.ENHANCED_CACHE_MANAGER`, its name can also be specified by `spring.cache.enhanced.enhancedCacheManagerName` in spring application.yml.
With spring-enhanced-cache, there will be an EnhancedCacheManager created and injected as a spring bean automaticly. The default name of the EnhancedCacheManager is `cn.howaric.cache.enhancer.EnhancedCacheManager.ENHANCED_CACHE_MANAGER`, it can also be specified by `spring.cache.enhanced.enhancedCacheManagerName` in spring application.yml.

```yaml
spring:
Expand All @@ -47,11 +52,11 @@ spring:
redis:
time-to-live: 10000 # time unit is millis
enhanced:
enhanced-cache-manager-name: "enhancedCacheManager" # name of the cache manager
# enhanced-cache-manager-name: "customEnhancedCacheManager" # name of the cache manager
delay-time: 2000 # means deleting cache eviction again after 2s, default is 5s
```

Then you can just use this CacheManager in @CacheEvict annotation, and @CacheEvict will trigger a delayed eviction of the cache in the specific delay time.
By specifying this enhanced CacheManager in @CacheEvict annotation, it will trigger a delayed eviction of the cache in the specific delay time.

```java
@CacheEvict(key = "#p0.username", cacheManager = EnhancedCacheManager.ENHANCED_CACHE_MANAGER)
Expand All @@ -60,22 +65,22 @@ public void updateUser(User user) {
}
```

## Trouleshooting
## Troubleshooting

1. How to make sure the EnhancedCacheManager really trigger the delayed eviction of cache?

You can just open the debug log for package `cn.howaric.cache`, then you will see the related logs.
You can just open the debug log for package `cn.howaric.cache.enhancer`, then you will see the related logs.

```yaml
logging:
level:
cn.howaric.cache: debug
cn.howaric.cache.enhancer: debug
```

Logs example,

```tex
2022-03-07 21:56:40.780 DEBUG 85337 --- [nio-8080-exec-1] c.g.h.c.e.listener.ListenableCache : Evict cache
2022-03-07 21:56:40.782 DEBUG 85337 --- [nio-8080-exec-1] c.g.h.c.e.listener.ListenableCache : Evict cache delayed operation published
2022-03-07 21:56:42.804 DEBUG 85337 --- [pool-1-thread-1] c.g.h.c.e.listener.EvictCacheOperation : Re-evict cache
2022-03-07 21:56:40.780 DEBUG 85337 --- [nio-8080-exec-1] c.h.c.e.listener.ListenableCache : Evict cache
2022-03-07 21:56:40.782 DEBUG 85337 --- [nio-8080-exec-1] c.h.c.e.listener.ListenableCache : Evict cache delayed operation published
2022-03-07 21:56:42.804 DEBUG 85337 --- [pool-1-thread-1] c.h.c.e.listener.EvictCacheOperation : Re-evict cache
```

0 comments on commit 421746f

Please sign in to comment.