In this recipe, we chose to implement the repository tier as an abstract interface. Designing this sort of structure allows you to, in theory, have multiple implementations of the repository interface that can be swapped in and out effortlessly. The following diagram shows four of the most popular types of repositories that we could have configured:
In fact, this same abstract class could be used to store data in a database, in one or more files, or in a RESTful web service. In this recipe, we chose to implement the simplest option, InMemoryCache, which is nothing more than a fancy Map. The interesting thing about this class is that it represents a unified interface that can be used regardless of the actual destination of the data.
The higher layers in the n-tier architecture do not need to know how the data is stored, just that it is stored. Everything else, from their perspective, is an implementation detail.
Another requirement of the repository layer is that it cannot...