Caching Data Objects when using Repository/Service Pattern and MVC

前端 未结 4 1977
囚心锁ツ
囚心锁ツ 2020-12-12 19:03

I have an MVC-based site, which is using a Repository/Service pattern for data access. The Services are written to be using in a majority of applications (console, winform,

4条回答
  •  既然无缘
    2020-12-12 19:43

    The easiest way would be to handle caching in your repository provider. That way you don't have to change out any code in the rest of your app; it will be oblivious to the fact that the data was served out of a cache rather than the repository.

    So, I'd create an interface that the controllers use to communicate with the backend, and in the implementation of this I'd add the caching logic. Wrap it all up in a nice bow with some DI, and your app will be set for easy testing.

提交回复
热议问题