Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to use @CachePut to update the cache after method execution.
Spring Boot
@CachePut(value = "users", key = "#user.id") public User [1](User user) { // update user logic return user; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @CachePut on a method that only retrieves data without updating.
Choosing a method name that does not indicate updating.
✗ Incorrect
The method annotated with @CachePut should update the cache, so the method name 'updateUser' fits the purpose.
2fill in blank
mediumComplete the code to specify the cache key using SpEL expression in @CachePut.
Spring Boot
@CachePut(value = "products", key = "[1]") public Product updateProduct(Product product) { // update logic return product; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting '#' in the SpEL expression.
Using a variable name not matching the method parameter.
✗ Incorrect
The key expression in @CachePut uses SpEL and must reference the method parameter with #, so '#product.id' is correct.
3fill in blank
hardFix the error in the @CachePut annotation to correctly update the cache for the method.
Spring Boot
@CachePut(value = "orders", key = "[1]") public Order updateOrder(Order order) { // update order logic return order; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a key expression without '#' symbol.
Referencing a variable name not declared as a parameter.
✗ Incorrect
The key must use SpEL with '#' and match the method parameter name, so '#order.id' is correct.
4fill in blank
hardFill both blanks to correctly use @CachePut with cache name and key expression.
Spring Boot
@CachePut(value = "[1]", key = "[2]") public Customer updateCustomer(Customer customer) { return customer; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong cache name that does not match the entity.
Incorrect key expression without '#' or wrong parameter name.
✗ Incorrect
The cache name is 'customers' and the key expression must reference the method parameter with '#customer.id'.
5fill in blank
hardFill all three blanks to create a method that updates cache with @CachePut, specifying cache name, key, and method name.
Spring Boot
@CachePut(value = "[1]", key = "[2]") public Product [3](Product product) { // update logic return product; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent cache names.
Incorrect key expressions missing '#'.
Method names that do not reflect updating.
✗ Incorrect
The cache name is 'products', the key expression is '#product.id', and the method name 'updateProduct' clearly indicates updating.