Cache layer for MVC - Model or controller?

前端 未结 2 423
梦毁少年i
梦毁少年i 2021-02-01 22:24

I am having some second thoughts about where to implement the caching part. Where is the most appropriate place to implement it, you think?

Inside every model, or in the

2条回答
  •  余生分开走
    2021-02-01 22:54

    I would keep my caching responsibilities firmly within the model. It is none of the controller's or view's business where the model is getting data. All they care about is that when data is requested, data is provided - this is how the MVC paradigm is supposed to work.

    Abstract your mem_cache functionality into the parent model class. It will cut down on the amount of code you need to write (code = time = money), simplify modifications to the system, and eliminate the number of bugs you produce per model that you build (see previous formula).

    Standardize, standardize.

提交回复
热议问题