H
H
HaruAtari2014-02-13 18:41:19
Yii
HaruAtari, 2014-02-13 18:41:19

Where to cache data: in the model or in the controller?

There is a site on Yii. The application is built on the principle of "thick model, thin controller". Completely all operations are carried out in models. The controller only says what to return and launches the necessary views.
There was a question about caching. And so I thought, where is the right place to cache data? It is easier to do this in the model because it will be easier to monitor the validity of the cache. But at the same time, this will unnecessarily complicate models that are already not weak.
Tell me where is the best place to cache data?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
O
OnYourLips, 2014-02-13
@HaruAtari

Can be cached in the model.
It is possible in the controller.
It is possible in the form.
You can use the front controller.
And all this is done by different means and for different purposes.
Depends on the task.

Y
Yuri Morozov, 2014-02-13
@metamorph

...and taking into account the fact that we can sometimes request cached data (for the frontend) and sometimes not cached data (for the admin), it becomes quite fun :)
In general, it depends on the situation. Throw in "how to do it right in MVC", think about how to do it right in application logic.
Now it has somehow become fashionable to follow meaningless design patterns and overload models with functionality (a bunch of methods "returnSuchData(), returnOtherData()), while through the controller it would be easier and clearer to decide.

F
FanatPHP, 2014-02-13
@FanatPHP

In the general case, if we talk about data , then the model , in a good way, should be able to do this transparently. She was asked for data - and where she got them from is not our business.

V
Von_Der_Shulenburg, 2014-02-14
@Von_Der_Shulenburg

With the correct architecture, the controller should not know anything at all about caching and working with the database. All this is done at the model level.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question