Skip to content

Commit

Permalink
feat : handle exception in cache
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Dec 18, 2024
1 parent 833f954 commit d42baa5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
"workbox-core": "7.3.0",
"workbox-precaching": "7.3.0"
},
"hash": "9c1312c261083d399cbb80453e62a52e287d8e2a587ecedd137dd0ee750baab5"
"hash": "d645f4602d1ea276dc5770a91071154295d863732c497da11194102629504cfd"
},
"overrides": {
"@vaadin/bundles": "$@vaadin/bundles",
Expand Down
34 changes: 33 additions & 1 deletion src/main/java/com/app/folioman/config/redis/RedisConfig.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package com.app.folioman.config.redis;

import org.springframework.cache.Cache;
import org.springframework.cache.annotation.CachingConfigurer;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.interceptor.CacheErrorHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheWriter;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.lang.Nullable;

@Configuration(proxyBeanMethods = false)
@EnableCaching
class RedisConfig {
class RedisConfig implements CachingConfigurer {

@Bean
RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
Expand All @@ -27,4 +31,32 @@ CustomRedisCacheManager cacheManager(RedisConnectionFactory redisConnectionFacto
RedisCacheWriter redisCacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory);
return new CustomRedisCacheManager(redisCacheWriter, redisConnectionFactory, monitor);
}

@Override
public CacheErrorHandler errorHandler() {

return new CacheErrorHandler() {

@Override
public void handleCacheGetError(RuntimeException exception, Cache cache, Object key) {
// your custom error handling logic
}

@Override
public void handleCachePutError(
RuntimeException exception, Cache cache, Object key, @Nullable Object value) {
// your custom error handling logic
}

@Override
public void handleCacheEvictError(RuntimeException exception, Cache cache, Object key) {
// your custom error handling logic
}

@Override
public void handleCacheClearError(RuntimeException exception, Cache cache) {
// your custom error handling logic
}
};
}
}

0 comments on commit d42baa5

Please sign in to comment.