From 421746f658842a0f80f1662141192498c3461e67 Mon Sep 17 00:00:00 2001 From: howaric Date: Wed, 9 Mar 2022 20:19:20 +0800 Subject: [PATCH] Update README.md --- README.md | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 43dd447..5800fd7 100644 --- a/README.md +++ b/README.md @@ -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 cn.howaric.cache spring-boot-starter-cache-enhancer - 0.0.1 + ${latest.version} ``` ->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 @@ -36,9 +39,11 @@ Add a cache implementation such as redis: ``` -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: @@ -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) @@ -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 ```