13.5 · The repository pattern and cache design

How the rest of the app sees storage decides whether you can change it. A thin repository and a deliberately designed cache keep the framework behind a door.

Mental model. The domain asks for things (users, orders); only the repository knows they live in rows. Caches are a policy (size, age, eviction), not a dictionary.

Boundaries

Repositories and mapping between storage and domain.

  1. What is the repository pattern, and why map storage models to domain models? 13.5.1 · L3
    A repository is an object (usually behind a protocol) that offers the rest of the app a collection-like interface to a kind of data: func user(id:) async…

Caches

Memory and disk caches, TTL and eviction.

  1. How do you design a cache: memory and disk layers, TTL, eviction, and what to key it by? 13.5.2 · L5
    A cache trades memory or disk for time, and its policy is the design. Decide five things. Key: everything that changes the value, for example the URL and the…

More in Persistence & data