Probably many people know what MVC is, if not, then
Wikipedia will help you. It is no secret that most web applications use exactly this well-proven architecture.
But now I have a question that I hope to get an answer from habraprogrammers: how can I cache when using MVC?
It is clear that the model can be used to cache intermediate calculations, queries (if
This does not deal with the database), some data.
')
And which of the three components should be responsible for caching the final html-code?
The ideal caching case is the algorithm:
1. Check the current version in the cache
2. If yes, then return it
3. If not, get data from different sources.
4. Process data
5. Create and write html to a file (or other data storage) cache
6. Return the final html-code
Let's look at a few examples:
1. If the caching performs the presentation, then the cached code is given to the browser, but the model still works out because it knows nothing about it.
2. If caching occurs in a model, then there is confusion, since the model should return figuratively speaking an array of data, and not a piece of html-code.
3. And the controller, based on its role, should not do it at all ...
It is very easy to cache the whole page with any architecture of the system core, but nowadays there are very few sites where the pages do not contain any kind of dynamic blocks (voting, banner systems (with rotation), informers, and even life complicates authorization when the code is unique for each user).
How within MVC to make the final code of page blocks be cached and the model did not perform data sampling and processing for this block, and for the rest, of course, it was executed?
UPD: The main problem is to find extraordinary caching paths. This is due to the fact that there is a ready-made site (a large regional portal), the code of which cannot be completely rewritten (for many reasons). It is necessary to hang the possibility of caching on the ready-made functionality. If it were not for MVC, then I would have done it in a short period of time. Therefore the question has rested against implementation of caching at architecture MVC.
I look forward to your advice!