HMVC
Материал из YourcmcWiki
Версия от 14:14, 16 мая 2016; VitaliyFilippov (обсуждение | вклад)
Об одном правильном подходе к HMVC (Hierarchical MVC).
English
Our own HMVC. Each controller has 2 methods:
- check() — always runs before trying to load the output from cache:
- handles modification requests (and redirects after applying changes),
- validates parameters, redirects to handsome URLs
- calculates cache key
- also it MAY calculate cache tags and do subrequests if it wants to
- run() — runs only on cache miss:
- calculates output HTML
- MAY calculate cache tags and do subrequests if check() does not want to :-)
Request workflow:
- Create main controller
- Create layout controller
- Starting with the main controller:
- Call check()
- Try to load output from cache
- If loaded and valid, and if check() did not call subrequest() — load subrequest records from cached output
- If not loaded:
- If check() calculated some cache tags — do NOT reset them
- Call run()
- Save output, tags and subrequest records to cache
- Do (3) with all subrequest controllers
- Replace placeholders in output with subrequest outputs
- Do (3) with the layout controller
- Calculate Last-Modified from cache tags of all controllers (each tag flush updates its modification time)
- Compare Last-Modified with the requested If-Modified-Since and send HTTP 304 if not modified
- Send generated output normally