0
0
Spring Bootframework~20 mins

Cache key strategies in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Cache Key Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding default cache key generation in Spring Boot
In Spring Boot's caching abstraction, what does the default cache key consist of when no custom key is specified?
AOnly the first method parameter value
BThe method parameters
CA random UUID generated for each cache entry
DThe method name as a string
Attempts:
2 left
💡 Hint
Think about what uniquely identifies a method call with parameters in caching.
component_behavior
intermediate
2:00remaining
Effect of @Cacheable key attribute with SpEL expression
Given the following method in a Spring Boot service:
@Cacheable(value = "users", key = "#user.id")
public User getUser(User user) { ... }
What will be used as the cache key when this method is called?
Spring Boot
@Cacheable(value = "users", key = "#user.id")
public User getUser(User user) { return user; }
AThe id property of the user object passed as parameter
BThe default key generated from all method parameters
CThe entire user object serialized
DThe string "#user.id" literally
Attempts:
2 left
💡 Hint
Look at the SpEL expression inside the key attribute.
📝 Syntax
advanced
2:00remaining
Correct SpEL syntax for composite cache key
Which of the following @Cacheable key expressions correctly creates a composite key from two method parameters named 'id' and 'type'?
A#id & #type
B#id, #type
C{#id, #type}
D#id + '-' + #type
Attempts:
2 left
💡 Hint
Think about how to concatenate strings in SpEL.
🔧 Debug
advanced
2:00remaining
Identifying cache key error causing cache misses
A developer uses @Cacheable with key = "#user" on a method with a User parameter. The cache never hits even when called with the same User object. What is the most likely cause?
Spring Boot
@Cacheable(value = "users", key = "#user")
public User getUser(User user) { ... }
AUser class does not override equals() and hashCode(), so keys differ despite same data
BThe key expression "#user" is invalid SpEL syntax causing runtime error
CThe cache value name "users" is reserved and causes conflicts
DThe method parameter must be primitive types only for caching
Attempts:
2 left
💡 Hint
Think about how objects are compared as keys in caches.
state_output
expert
3:00remaining
Cache key behavior with complex nested parameters
Consider a method annotated with @Cacheable(value = "orders") that takes an Order object with nested Customer object. The key is set as "#order.customer.id". If two different Order objects have the same Customer id, what will happen when caching?
Spring Boot
@Cacheable(value = "orders", key = "#order.customer.id")
public Order getOrder(Order order) { ... }
AEach call creates a separate cache entry because the Order objects differ
BCache will throw an error due to nested property access in key
CBoth calls will share the same cache entry because the key is the same customer id
DCache will ignore the key and use default key generation
Attempts:
2 left
💡 Hint
Focus on what the key expression evaluates to.