LRU Cache for Expensive Point-in-Time Factor Computations
Last updated: November 29, 2026
Quick Overview
Implement an LRU cache in front of a function that computes a factor's values for a given date, with a fixed capacity, hit and miss counters, and invalidation of one factor's entries.
Voleon
November 29, 20260
0
0 solved
Implement an LRU cache in front of a function that computes a factor's values for a given date, with a fixed capacity, hit and miss counters, and invalidation of one factor's entries.
Researchers at Voleon recompute the same factor slices repeatedly during interactive work, so caching is a practical memory and performance topic. The interviewer checks that you pick an O(1) structure, evict correctly, and think about invalidation and memory limits.
What the Interviewer Expects
- Choose an ordered hash map or hash map plus doubly linked list
- Make get and insert O(1)
- Evict the least recently used entry when over capacity
- Support targeted invalidation
- Discuss sizing by memory rather than entry count
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How would you bound the cache by bytes instead of entries?
- How would you make it safe for concurrent readers?
- When would LRU be a bad eviction policy for backtests that scan dates in order?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
Key (factor, date). On miss, call compute, store, and evict the least recently used entry if over capacity. On hit, mark the entry as most recently used. Expose hit and miss counts. `invalidate(fa...
High-Level Design
collections.OrderedDict keeps insertion order and supports move_to_end and popitem(last=False) in O(1), so it is exactly a hash map plus doubly linked list. Without it, you would build the linke...