本文阅读量 次
1. Spring Cache¶
1.1 基本注解¶
注解 | 说明 | 示例 | 备注 |
---|---|---|---|
@Cacheable | 缓存结果 | ||
@CacheConfig | 统一设置配置 | ||
@CacheEvict | 失效缓存结果 | ||
@CachePut | 更新缓存 | ||
@Caching | 增加多重注解 |
1.1.1 @Cacheable
示例¶
@Cacheable("books")
public Book findBook(ISBN isbn) {...}
1.1.2 @CacheEvict
示例¶
@CacheEvict(cacheNames="books", allEntries=true)
public void loadBooks(InputStream batch)
1.1.3 @CachePut
示例¶
@CachePut(cacheNames="book", key="#isbn")
public Book updateBook(ISBN isbn, BookDescriptor descriptor)
1.1.4 @Caching
示例¶
@Caching(evict = { @CacheEvict("primary"), @CacheEvict(cacheNames="secondary", key="#p0") })
public Book importBooks(String deposit, Date date)
1.1.5 @CacheConfig
示例¶
@CacheConfig("books")
public class BookRepositoryImpl implements BookRepository {
@Cacheable
public Book findBook(ISBN isbn) {...}
}