-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat) enable redis cache on application, embedded cache on tests
- Loading branch information
1 parent
04f991f
commit a911f6a
Showing
14 changed files
with
134 additions
and
11 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
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,28 @@ | ||
package manon.app.cache; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.springframework.cache.interceptor.KeyGenerator; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class CommonCacheConfig { | ||
|
||
/** Key generator name: generate a unique key of the class name, the method name, and all method parameters appended. */ | ||
public static final String KEY_GENERATOR_FULL = "KEY_GENERATOR_FULL"; | ||
|
||
/** Generate a unique key of the class name, the method name, and all method parameters appended. */ | ||
@NotNull | ||
@Bean(name = KEY_GENERATOR_FULL) | ||
public KeyGenerator keyGenerator() { | ||
return (o, method, objects) -> { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append(o.getClass().getName()); | ||
sb.append(method.getName()); | ||
for (Object obj : objects) { | ||
sb.append(obj.toString()); | ||
} | ||
return sb.toString(); | ||
}; | ||
} | ||
} |
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,22 @@ | ||
package manon.app.cache; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.springframework.cache.CacheManager; | ||
import org.springframework.cache.annotation.CachingConfigurerSupport; | ||
import org.springframework.cache.concurrent.ConcurrentMapCacheManager; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
|
||
import static manon.app.config.SpringProfiles.EMBEDDED_CACHE; | ||
|
||
@Configuration | ||
@Profile(EMBEDDED_CACHE) | ||
public class EmbeddedCacheConfig extends CachingConfigurerSupport { | ||
|
||
@NotNull | ||
@Bean | ||
public CacheManager cacheManager() { | ||
return new ConcurrentMapCacheManager(); | ||
} | ||
} |
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,28 @@ | ||
package manon.app.cache; | ||
|
||
import org.springframework.cache.annotation.CachingConfigurerSupport; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.data.redis.cache.RedisCacheConfiguration; | ||
import org.springframework.data.redis.cache.RedisCacheManager; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
|
||
import java.time.Duration; | ||
|
||
import static manon.app.config.SpringProfiles.REDIS_CACHE; | ||
|
||
@Configuration | ||
@Profile(REDIS_CACHE) | ||
public class RedisCacheConfig extends CachingConfigurerSupport { | ||
|
||
@Bean | ||
public RedisCacheManager cacheManager(RedisTemplate redisTemplate) { | ||
RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig() | ||
.entryTtl(Duration.ofDays(1)) | ||
.prefixKeysWith("manon_"); | ||
return RedisCacheManager.builder(redisTemplate.getConnectionFactory()) | ||
.cacheDefaults(config) | ||
.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
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