diff --git a/springBootBlog/src/main/java/com/yen/mdblog/BlogApplication.java b/springBootBlog/src/main/java/com/yen/mdblog/BlogApplication.java index 8a137c626..dbdfad312 100644 --- a/springBootBlog/src/main/java/com/yen/mdblog/BlogApplication.java +++ b/springBootBlog/src/main/java/com/yen/mdblog/BlogApplication.java @@ -2,7 +2,9 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cache.annotation.EnableCaching; +@EnableCaching @SpringBootApplication public class BlogApplication { public static void main(String[] args) { diff --git a/springBootBlog/src/main/java/com/yen/mdblog/config/RedisCacheConfig.java b/springBootBlog/src/main/java/com/yen/mdblog/config/RedisCacheConfig.java new file mode 100644 index 000000000..68afe3fff --- /dev/null +++ b/springBootBlog/src/main/java/com/yen/mdblog/config/RedisCacheConfig.java @@ -0,0 +1,27 @@ +package com.yen.mdblog.config; + +import org.springframework.cache.CacheManager; +import org.springframework.cache.annotation.EnableCaching; +//import org.springframework.cache.redis.RedisCacheManager; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.cache.RedisCacheManager; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; + +@Configuration +@EnableCaching +public class RedisCacheConfig { + + @Bean + public RedisTemplate redisTemplate(RedisConnectionFactory connectionFactory) { + RedisTemplate template = new RedisTemplate<>(); + template.setConnectionFactory(connectionFactory); + return template; + } + + @Bean + public CacheManager cacheManager(RedisConnectionFactory connectionFactory) { + return RedisCacheManager.builder(connectionFactory).build(); + } +} \ No newline at end of file