Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to enable caching on the method.
Spring Boot
@Cacheable(value = "books") public Book [1](Long id) { // method body }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method name that implies writing or deleting data.
Not matching the method name to the caching purpose.
✗ Incorrect
The method name 'getBookById' is a common naming for read operations suitable for caching.
2fill in blank
mediumComplete the annotation to specify the cache name.
Spring Boot
@Cacheable(value = "[1]") public Book getBookById(Long id) { // method body }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a cache name unrelated to the method's data.
Using plural vs singular inconsistently.
✗ Incorrect
The cache name 'books' matches the data type being cached.
3fill in blank
hardFix the error in the cache key expression.
Spring Boot
@Cacheable(value = "books", key = "#[1]") public Book getBookById(Long id) { // method body }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a key that does not match any method parameter.
Forgetting the '#' symbol in the key expression.
✗ Incorrect
The parameter name is 'id', so the key expression must use '#id' to cache by method argument.
4fill in blank
hardFill both blanks to create a cacheable method with a custom key.
Spring Boot
@Cacheable(value = "books", key = "#[1]") public Book [2](Long bookId) { // method body }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatch between key and parameter name.
Using a method name that implies writing data.
✗ Incorrect
The key uses the parameter 'bookId' and the method name 'findBook' fits a read operation.
5fill in blank
hardFill all three blanks to define a cacheable method with a cache name, key, and method name.
Spring Boot
@Cacheable(value = "[1]", key = "#[2]") public Book [3](Long id) { // method body }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a cache name unrelated to the method.
Key not matching the parameter name.
Method name not indicating a read operation.
✗ Incorrect
The cache name is 'books', the key matches the parameter 'id', and the method name is 'getBookById'.