Question
Complete an LRU cache that memoizes arbitrary function calls and survives process restart using an append-only write-ahead log.
```python
class LRU:
def __init__(self, capacity: int, log_path: str): ...
def generate_key(self, func, args: tuple, kwargs: dict): ...
def call(self, func, *args, **kwargs): ...
```
## Requirements
- Keys must include function identity and recursively canonicalized arguments.
- Keyword insertion order must not affect identity; nested lists and dictionaries must be supported.
- Hits return the stored value without executing the function and become most-recently used.
- Append a complete record for every access before returning, so replay reconstructs values and recency.
- Enforce capacity during both live operation and replay.
- Ignore a malformed final record caused by an interrupted append, but do not silently skip earlier corruption.
- Correctly cache falsey values.
Assume a single process and JSON-compatible inputs and outputs in the base version.
## Staged follow-ups
1. Fix deterministic key generation and implement ordinary LRU behavior.
2. Add replayable durability while preserving recency order.
3. Bound recovery time with snapshots and safe log compaction.
4. Discuss `flush` versus `fsync`, batched durability, multi-process locking, and exactly what a successful call guarantees.
5. Design a migration path when the record schema changes.