Nov 01, 2011
Before delving into Design patterns, let us think architecture from resilience perspective.
At the application architecture level, I would recommend to focus on seperation of concenrs, that Data services layer should always do operations related to data.
For Design Patterns you have the answer from Rajesh, which is always within a specific layer.
From 3-tier perspective, you should have a layer to manage Caching, between business and data services layer.
That UI -> BSL-> Optionally (caching Layer)-> DB
Once the data is retrived by business layer, it may optionally can pass in to Caching layer, which will satisfy caching requirement.
Once Cached, then pass the data back to UI layer.
Hope this helps.
Oct 28, 2011
If you have the repository patterns at the DB layer then you can easily implement a cache repository and plugin via some IOC container or by poor man's dependency injection..
Basically its a combination of factory + strategy pattern. Factory to create instance and strategy to select the algorithm like getting from cache or Db.
You can also use variation of the above pattern as well.
In case your DB layer is not that flexible the quickest thing would be to introduce a caching facade service which interacts with the DB layer based on cache settings....