Product Catalog Cache with LRU Eviction and Per-Entry Expiry
Last updated: November 29, 2026
Quick Overview
Implement an in-process cache for a retail client's product catalog that holds at most N entries, evicts the least recently used entry when full, and treats each entry as missing once its time to live has passed.
EPAM Systems
November 29, 20260
0
0 solved
Implement an in-process cache for a retail client's product catalog that holds at most N entries, evicts the least recently used entry when full, and treats each entry as missing once its time to live has passed.
Caching in front of slow client systems (ERP, PIM, mainframe-backed APIs) is a common EPAM project concern, so this mixes a classic data structure with a production detail. The interviewer checks O(1) operations, correct interaction between recency and expiry, and testability through an injected clock.
What the Interviewer Expects
- O(1) average `get` and `put` using a hash map plus recency order
- Expired entries are never returned, even if not yet evicted
- Overwriting a key refreshes both value and TTL and recency
- Inject the clock so expiry can be unit tested without sleeping
- Discuss when to purge expired entries (lazily on access versus on overflow)
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you make this safe for concurrent request threads?
- How would you avoid a thundering herd when a hot SKU expires?
- When would you move this to Redis, and what changes?
- How would you report hit rate and eviction counts?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
get(key) returns the value or a default if missing or expired; a successful get marks the key most recent. put(key, value, ttl=None) inserts or replaces, using a default TTL. Capacity is a hard li...
High-Level Design
An OrderedDict gives a hash map with a doubly linked recency list: move_to_end is O(1) and popitem(last=False) removes the least recent in O(1). Each value carries an absolute expires_at. Expi...