Comparison
Cache-asidevsRepository pattern
Cache-aside
you check the cache, miss, go and read the database yourself, and write the value back before you return it.
The application owns the cache: on a miss it loads from the store and populates the cache itself. It is the usual default because the cache can go down without taking reads with it, and because nothing is cached that nobody asked for. The costs are that every miss pays database latency plus a write, and that two requests missing the same key at the same moment both hit the database.
Full entry →Repository pattern
the code asks for the customer as if from an in-memory collection, and where it actually came from is somewhere else.
An abstraction that presents stored aggregates as though they were a collection, so domain code queries objects rather than rows. It is a domain-driven design idea: one repository per aggregate root, with methods named in the language of the domain, not one per table. That is the real difference from a DAO — a repository is defined by the model it serves, a DAO by the storage it wraps — and it is lost the moment a repository grows a method per query the UI happens to need.
Full entry →