@Cacheable 可以自动生成缓存,一次在开发中使用使用该注解,本来以为重启后缓存就消失了,可是重启后,原来缓存的值还在,后来查找redis,发现缓存到redis中,如果我们不想持久化,仅仅缓存到内存,可以通过实现CacheManager,指定缓存的位置,指定ConcurrentMapCache

@Cacheable(value = "sampleCacheTest", unless = "null == #result", key = "#counterId + '&' + #tradeType")
    public ResDTO getBankOrder(int tradeType) {
        try {
            ResDTO resdto = getOrderFormat(tradeType);;
            return resdto;
        } catch (Exception e) {
            return null;
        }
    }

    @Bean
    public CacheManager cacheManager() {
        SimpleCacheManager cacheManager = new SimpleCacheManager();
        cacheManager.setCaches(Arrays.asList(new ConcurrentMapCache("sampleCacheTest")));
        cacheManager.afterPropertiesSet();
        return cacheManager;
    }


---------------------