小编Sak*_*sho的帖子

Spring Boot EnableCaching和Cacheable注释无效

我想将主数据缓存到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)

java spring caching redis spring-boot

5
推荐指数
1
解决办法
5040
查看次数

标签 统计

caching ×1

java ×1

redis ×1

spring ×1

spring-boot ×1