@Configuration
@EnableCaching
public class CacheConfig extends CachingConfigurerSupport {
@Bean
public CacheManager cacheManager() {
return new ConcurrentMapCacheManager();
}
@Bean
public KeyGenerator keyGenerator() {
return new SimpleKeyGenerator();
}
}
@Service
public class ProductService {
@Cacheable("productCache")
public Product getProductById(int id) {
return product;
}
@CachePut(value = "productCache", key = "#product.id")
public Product saveProduct(Product product) {
return product;
}
}