LRU Cache with TTL and Tenant Isolation
Last updated: December 9, 2025
Quick Overview
Implement an LRU cache that supports per-entry TTL expiration and tenant isolation, ensuring one tenant's cache usage cannot evict another tenant's entries.
Wiz
December 9, 202510
9
2,596 solved
Implement an LRU cache that supports per-entry TTL expiration and tenant isolation, ensuring one tenant's cache usage cannot evict another tenant's entries.
Caching is critical for Wiz's scanning performance, but in a multi-tenant system, cache design requires careful isolation. A large tenant's scan results should not evict a small tenant's cached data. This problem tests your ability to extend a classic data structure (LRU cache) with production requirements common in multi-tenant SaaS systems.
What the Interviewer Expects
- Implement a standard LRU cache with O(1) get/put operations
- Add TTL support with lazy expiration
- Implement per-tenant capacity limits within the global cache
- Handle edge cases: expired entries, tenant quota exceeded, empty cache
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 implement proactive TTL cleanup without impacting read latency?
- What if tenants have different cache priorities?
- How would you distribute this cache across multiple servers?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Implementation
```python import time from collections import OrderedDict, defaultdict class TenantLRUCache: def __init__(self, global_capacity, per_tenant_capac...
Design Tradeoffs
Per-tenant eviction (_evict_tenant_lru) is O(n) in worst case because we scan for the tenant's oldest entry. For production, maintain a per-tenant LRU...