Question

Difficulty: MediumImplement Azure Cache for Redis Configuration and Data Patterns

A gaming company uses an Azure Cache for Redis instance to store real-time leaderboard statistics and user session states. The leaderboard keys must persist indefinitely and are not configured with a Time-to-Live (TTL). The user session keys are configured with a sliding TTL. During peak gaming events, the cache reaches its memory limit, causing write operations to fail. You need to configure the cache to automatically evict the user session keys that are accessed the least frequently to free up memory, while ensuring that the leaderboard keys are never evicted. Which eviction policy should you configure to meet these requirements?

  1. volatile-lfuAnswer
  2. B
    allkeys-lfu
  3. C
    volatile-lru
  4. D
    noeviction

Answer

volatile-lfu
The volatile-lfu policy evicts the least frequently used keys among those that have an expiration (TTL) set. Because only the user session keys have a TTL configured, and the leaderboard keys do not, this policy guarantees that leaderboard keys are preserved. Additionally, it uses the Least Frequently Used (LFU) algorithm, satisfying the requirement to evict keys based on access frequency.

Step-by-Step Solution

1
Analyze key configuration constraints.
Leaderboard keys do not have a TTL and must be protected. User session keys have a TTL and can be evicted.
This limits the choice of eviction policies to the volatile family, which only target keys with an expiration set.
2
Determine the access pattern requirement for eviction.
The keys that are accessed the least frequently must be evicted.
This indicates that a Least Frequently Used (LFU) algorithm must be used rather than a Least Recently Used (LRU) algorithm.
3
Select the policy combining volatile scope and LFU algorithm.
The volatile-lfu policy is selected.
This policy ensures that only keys with an expiration set are evaluated using the LFU algorithm.

Key Concept

Selecting the correct Redis eviction policy based on TTL configuration and access patterns to prevent data loss of critical keys.
Rate this question