有人可以告诉我下面的实现有什么问题。我正在尝试删除整个缓存,其次,我想预填充/填充缓存。但是,当执行这两种方法时,我在下面仅删除两个缓存,而不是预填充/启动缓存。任何想法?
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
@Cacheable(cacheNames = "cacheOne")
List<User> cacheOne() throws Exception {...}
@Cacheable(cacheNames = "cacheOne")
List<Book> cacheTwo() throws Exception {...}
@Caching (
evict = {
@CacheEvict(cacheNames = "cacheOne", allEntries = true),
@CacheEvict(cacheNames = "CacheTwo", allEntries = true)
}
)
void clearAndReloadEntireCache() throws Exception
{
// Trying to reload cacheOne and cacheTwo inside this method
// Is this even possible? if not what is the correct approach?
cacheOne();
cacheTwo();
}
我有 spring boot 应用程序(v1.4.0),更重要的是,利用以下依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
<version>1.0.0</version>
</dependency>