我想将主数据缓存到Redis.
所以,我写了这些代码.
@Configuration
@EnableCaching
public class AppConfig extends CachingConfigurerSupport {
@Bean
@Autowired
public CacheManager cacheManager(RedisTemplate<Object, Object> redisTemplate) {
RedisCacheManager cacheManager = new RedisCacheManager(redisTemplate);
Map<String, Long> expires = new HashMap<>();
expires.put("cache.day", new Long(24 * 60 * 60));
cacheManager.setExpires(expires);
return cacheManager;
}
}
Run Code Online (Sandbox Code Playgroud)
和
package com.taisho.artifacts.repository.impl;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;
import java.util.ArrayList;
import java.util.List;
@Repository
public class TestRepository {
@Cacheable(value = "cache.day", key = "'cache.test'")
public List<String> getTest() {
List<String> list = new ArrayList<>();
list.add("test");
list.add("sample");
return list;
}
public void printTest() …
Run Code Online (Sandbox Code Playgroud)