Complete the code to specify a cache key using Spring's @Cacheable annotation.
@Cacheable(value = "users", key = "#[1]") public User getUserById(Long id) { // method body }
The cache key is set to the method parameter id using #id in the SpEL expression.
Complete the code to create a cache key based on multiple method parameters.
@Cacheable(value = "products", key = "#[1] + '-' + #[2]") public Product getProduct(String category, Long productId) { // method body }
The first part of the key uses the category parameter, combined with the productId parameter.
Fix the error in the cache key expression to correctly use the method parameter.
@Cacheable(value = "orders", key = "#[1]") public Order findOrder(Long orderId) { // method body }
The method parameter is named orderId, so the key expression must use #orderId.
Fill both blanks to create a cache key using two parameters separated by an underscore.
@Cacheable(value = "sessions", key = "#[1] + '_' + #[2]") public Session getSession(String userId, String sessionId) { // method body }
The cache key combines userId and sessionId separated by an underscore.
Fill all three blanks to create a cache key using a method parameter and a method call on it.
@Cacheable(value = "employees", key = "#[1] + '-' + #[2].[3]()") public Employee getEmployee(EmployeeId empId) { // method body }
The cache key uses the empId parameter and calls its toString() method.