Skip to content

Commit a76f45c

Browse files
committed
v0.3.0
- proxy classes - fixed ttl in Redis tag store - updated doc
1 parent 01c8fdf commit a76f45c

File tree

9 files changed

+98
-342
lines changed

9 files changed

+98
-342
lines changed

README.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ It allows you to group cached methods by tags and evict cache entries by one or
2727
<dependency>
2828
<groupId>io.github.intellinside</groupId>
2929
<artifactId>spring-boot-starter-cache-tags</artifactId>
30-
<version>0.2.0</version>
30+
<version>0.3.0</version>
3131
</dependency>
3232
```
3333

3434
#### Gradle
3535
```groovy
36-
implementation 'io.github.intellinside:spring-boot-starter-cache-tags:0.2.0'
36+
implementation 'io.github.intellinside:spring-boot-starter-cache-tags:0.3.0'
3737
```
3838

3939
### Basic Example
@@ -74,7 +74,7 @@ The `@CacheTags` annotation is used to associate one or more tags with cached me
7474
@CacheTags({
7575
"'product:' + #productId",
7676
"'category:' + #result.category",
77-
"'price-range:' + #result.priceRange"
77+
"price-range:#{#result.priceRange}"
7878
})
7979
public Product getProduct(Long productId) {
8080
return productRepository.findById(productId).orElse(null);
@@ -90,7 +90,7 @@ The `@EvictTags` annotation evicts all cache entries associated with specified t
9090
@EvictTags({
9191
"'product:' + #productId",
9292
"'category:' + #category",
93-
"'price-range:' + #result.priceRange"
93+
"price-range:#{#result.priceRange}"
9494
})
9595
public Product updateProduct(Long productId, String category) {
9696
// Update product in database
@@ -145,12 +145,6 @@ spring.redis.port=6379
145145
- Keys: `tag:{tagName}` (Redis Set)
146146
- Values: `{cacheName}:{key}` (serialized cache references)
147147

148-
Example Redis structure:
149-
```
150-
SET tag:user:123 users:user:123
151-
SET tag:user:123 users:permissions:123
152-
SET tag:admin admins:settings:456
153-
```
154148

155149
## Advanced Usage
156150

@@ -166,7 +160,7 @@ public class OrderService {
166160
@CacheTags({
167161
"'order:' + #orderId",
168162
"'customer:' + #customerId",
169-
"'status:' + #result.status"
163+
"status:#{#result.status}"
170164
})
171165
public Order getOrder(Long orderId, Long customerId) {
172166
return orderRepository.findById(orderId).orElse(null);
@@ -207,7 +201,7 @@ Generate tags based on result properties:
207201
@CacheTags({
208202
"'user:' + #id",
209203
"'role:' + #result.role",
210-
"'department:' + #result.department"
204+
"department:#{#result.department}"
211205
})
212206
public User getUserWithRoleAndDepartment(Long id) {
213207
return userRepository.findByIdWithRelations(id).orElse(null);
@@ -286,6 +280,10 @@ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file
286280

287281
## Changelog
288282

283+
### Version 0.3.0
284+
- Using proxies instead of wrappers for the cache manager and caches.
285+
- Fixed TTL support for the Redis backend when configured with Spring Boot
286+
289287
### Version 0.2.0
290288
- Added TTL support for Redis backend
291289
- Added support for Spring Template Expression syntax (#{...})

spring-boot-starter-cache-tags/src/main/java/io/github/intellinside/cache/tags/CacheTagsAutoConfiguration.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
1414
import org.springframework.cache.CacheManager;
1515
import org.springframework.context.annotation.Bean;
16-
import org.springframework.data.redis.cache.RedisCacheConfiguration;
16+
import org.springframework.data.redis.cache.RedisCacheManager;
1717
import org.springframework.data.redis.core.StringRedisTemplate;
1818

1919
/**
@@ -46,7 +46,6 @@
4646
*
4747
* @author intellinside
4848
* @see CacheTagsStore
49-
* @see TaggingCacheManager
5049
* @see CacheTagsAspect
5150
* @see EvictTagsAspect
5251
*/
@@ -80,8 +79,8 @@ public TaggingCacheManagerBeanPostProcessor taggingCacheManagerBeanPostProcessor
8079
@ConditionalOnProperty(value = "spring.cache.type", havingValue = "redis")
8180
@ConditionalOnBean(StringRedisTemplate.class)
8281
public CacheTagsStore redisCacheTagsStore(StringRedisTemplate redisTemplate,
83-
RedisCacheConfiguration redisCacheConfiguration) {
84-
return new RedisCacheTagStore(redisTemplate, redisCacheConfiguration);
82+
RedisCacheManager redisCacheManager) {
83+
return new RedisCacheTagStore(redisTemplate, redisCacheManager);
8584
}
8685

8786
/**

spring-cache-tags-redis/src/main/java/io/github/intellinside/cache/tags/store/RedisCacheTagStore.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import lombok.RequiredArgsConstructor;
44
import org.springframework.data.redis.cache.RedisCacheConfiguration;
5+
import org.springframework.data.redis.cache.RedisCacheManager;
56
import org.springframework.data.redis.core.RedisTemplate;
67

78
import java.time.Duration;
@@ -43,7 +44,7 @@
4344
@RequiredArgsConstructor
4445
public class RedisCacheTagStore implements CacheTagsStore {
4546
private final RedisTemplate<String, String> redisTemplate;
46-
private final RedisCacheConfiguration redisCacheConfiguration;
47+
private final RedisCacheManager redisCacheManager;
4748

4849
/**
4950
* Associates multiple tags with a cache key by storing them in Redis Sets.
@@ -59,13 +60,18 @@ public class RedisCacheTagStore implements CacheTagsStore {
5960
@Override
6061
public void addMappings(Set<String> tags, String cacheName, Object key) {
6162
String serializedKey = cacheName + ":" + key.toString();
63+
64+
RedisCacheConfiguration config = redisCacheManager.getCacheConfigurations()
65+
.getOrDefault(cacheName, RedisCacheConfiguration.defaultCacheConfig());
66+
6267
tags.stream()
6368
.map(tag -> "tag:" + tag)
6469
.forEach(tag -> {
6570
redisTemplate.opsForSet().add(tag, serializedKey);
66-
Duration timeToLive = redisCacheConfiguration.getTtlFunction().getTimeToLive(tag, null);
71+
72+
Duration timeToLive = config.getTtlFunction().getTimeToLive(tag, null);
6773
if (timeToLive.isPositive()) {
68-
redisTemplate.expire(tag, timeToLive);
74+
redisTemplate.expire(tag, timeToLive.plusMinutes(5));
6975
}
7076
});
7177
}

spring-cache-tags/src/main/java/io/github/intellinside/cache/tags/TaggingCache.java

Lines changed: 0 additions & 152 deletions
This file was deleted.

spring-cache-tags/src/main/java/io/github/intellinside/cache/tags/TaggingCacheManager.java

Lines changed: 0 additions & 83 deletions
This file was deleted.

0 commit comments

Comments
 (0)