如何删除整个缓存,然后预先填充缓存?

时间:2017-11-22 17:05:09

标签: spring-boot spring-cache ehcache-3

有人可以告诉我下面的实现有什么问题。我正在尝试删除整个缓存,其次,我想预先填充/填充缓存。但是,我在下面的内容只是删除两个缓存,而不是在执行这两个方法时预先填充/启动缓存。有什么想法吗?

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(); 
}

我是春季启动应用程序(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>

0 个答案:

没有答案
相关问题