Skills101
← All practice quizzes

Quiz: Spring Boot Caching

5 questions · new set on every retakeNo time limitPass: 60%+10 XP on first pass

Stop asking the database the same question a thousand times. Learn the cache-aside pattern in plain Java, then Spring's cache annotations, cache keys, expiry with Caffeine, and the mistakes that serve stale data.

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    In the cache-aside pattern, what happens on a cache miss?

  2. Question 2

    Which annotation always runs the method and stores its result in the cache?

  3. Question 3

    What does this print?

    import java.util.*;
    
    public class Main {
        static int dbCalls = 0;
        static Map<Integer, Integer> cache = new HashMap<>();
    
        static int fee(int courseId) {
            return cache.computeIfAbsent(courseId, id -> { dbCalls++; return id * 1000; });
        }
    
        public static void main(String[] args) {
            int total = fee(2) + fee(3) + fee(2) + fee(2);
            System.out.println(total + " " + dbCalls);
        }
    }
    
  4. Question 4

    A course title is updated in the database but the method that updates it has no cache annotation. What do users see?

  5. Question 5

    Why is @Cacheable ignored when findById is called from another method of the same class?

🎯 Today’s placement challenge — 10 questions, no login. Can you score 10/10?Take today’s challenge →