Caching Is an Adapter
Medium About 30 min Katabench Pro
A quote use case memoizes prices with an infrastructure cache inside its own loop, so a storage tactic lives in the application. Move caching into a decorator on the price port, and let the composition root decide how long each cache lives.
The full brief is part of Katabench Pro
Pro opens this kata's brief, its starter code and its grader. To see how the track works first, try Config Is Infrastructure, which is free.
How it is graded
You work across multiple files, and architecture rules turn the design boundaries into executable feedback.
What it practices
- Infrastructure as adapters
- Keep the ORM, clocks, caches, configuration and startup work out of the core as replaceable adapters.
- Decorator and composite patterns
- Wrap or nest objects behind one interface so behaviors stack and trees evaluate uniformly.
- Caching
- Put a cache in front of hot reads and decide what stays fresh.
Related katas
- Config Is Infrastructure Medium Free The shipping core reads a framework configuration type directly, welding the domain to infrastructure. Invert it behind a core-owned options port, and don't just rename the framework wrapper into the core, which trips a second rule.
- Cache the Hot Path Medium Free with account The product page hammers the database directly and melts under load. Design a read path with a load balancer, a cache and a replica, while keeping the client off the database.
- Evict the ORM From the Domain Hard Pro The domain entity inherits the ORM's base class and carries its own mapping, welding the most stable layer to a persistence framework. Moving the mapping alone won't free it; you must sever the base-type coupling and invert the persistence concern out.
- Fan Out Home Timelines Medium Free with account Reading every followed author on demand is collapsing the database. Publish post events and materialize timelines asynchronously.