2

我创建了一个使用 jcache 的 spring boot 项目,配置如下:

spring.cache.jcache.provider=org.ehcache.jsr107.EhcacheCachingProvider
spring.cache.jcache.config=classpath:ehcache.xml

我想动态创建缓存,我的代码是这样的:

@Autowired
lateinit var cacheManager: CacheManager;

@RequestMapping("setCache")
fun setCache(key: String, v: String) {
    cacheManager.getCache("test").put(key, v)
}

@RequestMapping("getCache")
fun getCache(key: String) {
    val  v = cacheManager.getCache("test")[key]
    println(v)
}

但是当缓存注释退出时我无法获取缓存,我想动态创建缓存。

4

0 回答 0