HMVC

Материал из YourcmcWiki
Перейти к: навигация, поиск

Об одном правильном подходе к 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:

  1. Create main controller
  2. Create layout controller
  3. Starting with the main controller:
    1. Call check()
    2. Try to load output from cache
    3. If loaded and valid, and if check() did not call subrequest() — load subrequest records from cached output
    4. If not loaded:
      1. If check() calculated some cache tags — do NOT reset them
      2. Call run()
      3. Save output, tags and subrequest records to cache
    5. Do (3) with all subrequest controllers
    6. Replace placeholders in output with subrequest outputs
  4. Do (3) with the layout controller
  5. Calculate Last-Modified from cache tags of all controllers (each tag flush updates its modification time)
  6. Compare Last-Modified with the requested If-Modified-Since and send HTTP 304 if not modified
  7. Send generated output normally