-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from gfa-cc-after/SCRUM-82
Scrum 82
- Loading branch information
Showing
9 changed files
with
82 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
backend/src/main/java/com/greenfoxacademy/backend/config/RedisConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.greenfoxacademy.backend.config; | ||
|
||
import java.time.Duration; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.cache.CacheManager; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.redis.cache.RedisCacheConfiguration; | ||
import org.springframework.data.redis.cache.RedisCacheManager; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
import org.springframework.data.redis.serializer.RedisSerializationContext; | ||
import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
|
||
/** | ||
* RedisConfig is a configuration class that defines the cache management strategy | ||
* for Redis in the Spring Boot application. It configures the Redis Cache Manager | ||
* and sets key serialization and expiration policies. | ||
*/ | ||
@Configuration | ||
@ConditionalOnProperty(name = "spring.cache.type", havingValue = "redis") | ||
public class RedisConfig { | ||
|
||
/** | ||
* The cacheManager method creates a RedisCacheManager bean that is used to manage. | ||
*/ | ||
@Bean | ||
public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) { | ||
RedisCacheConfiguration cacheConfig = RedisCacheConfiguration.defaultCacheConfig() | ||
.entryTtl(Duration.ofMinutes(3)) // Set TTL to 5 minutes | ||
.disableCachingNullValues() | ||
.serializeKeysWith( | ||
RedisSerializationContext | ||
.SerializationPair | ||
.fromSerializer(new StringRedisSerializer()) | ||
); | ||
|
||
return RedisCacheManager.builder(redisConnectionFactory) | ||
.cacheDefaults(cacheConfig) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters