Spring Boot 2 Caching¶
Types of cache¶
- In-memory caching
- Database caching
- Web server caching
- CDN caching
Cache annotations¶
@EnableCaching
@Cacheable
@Cacheable(value="books", key="#isbn") public Book findStoryBook(ISBN isbn, boolean checkWarehouse, boolean includeUsed) @Cacheable(value="books", key="#isbn.rawNumber") public Book findStoryBook (ISBN isbn, boolean checkWarehouse, boolean includeUsed) @Cacheable(value="books", key="T(classType).hash(#isbn)") public Book findStoryBook (ISBN isbn, boolean checkWarehouse, boolean includeUsed) @Cacheable(value="book", condition="#name.length < 50") public Book findStoryBook (String name)
@CachePut
@CacheEvict
@Caching
Register a cache engine¶
- JCache (JSR-107) (EhCache 3, Hazelcast, Infinispan, and others)
- EhCache 2.x
- Hazelcast
- Infinispan
- Couchbase
- Redis
- Caffeine
- Simple cache