24. 渲染缓存RenderCache

龸龴龲龰龮龸龴龪龦龥龢龠龞龛龘龔龐龢龌龋龸龴龊龆龄龂龁齾龂齻龢齷齳齱齯齭龞齫齩龸龴
齦齤齡齟齞齜齘龪龸龴龊龆齗齓齏龮齌齈齾龂龢齄齀鼾鼺齞齜齘鼷齓齏齯齭齫齩龸龴

鼵鼲齾龂齻龄龂龪龸龴龲龰鼱鼯鼲鼬鼫龪龢龸龴齾龂鼪鼦鼣齾龂齏鼟鼞鼝龢齷齳鼯鼬鼫龪龲龰鼙鼘鼕CacheableRenderArray黳黲黰黭黬黩鼞鼝黨黦

$elements = [  
      '#markup' => $elements['#markup'],  
      '#attached' => $elements['#attached'],  
      '#cache' => [  
        'contexts' => $elements['#cache']['contexts'],  
        'tags' => $elements['#cache']['tags'],  
        'max-age' => $elements['#cache']['max-age'],  
      ],  
    ];  

黥黤黲黣齦鼵黢黡$elements['#cache']['keys']
鼪鼦齄黉龢黅鼱黂麿麼鼷麹齾龂麶麴鼞鼝龪龦龥麲麱麯麮麭齓齏齷齳黲
麬麪$elements['#cache_properties']龢黣鼱鼾齟龲龰龢麞麚龠麹麗齾龂龪齜齘龪麞麖麓齓
麐齄麏Drupal\Core\Render\MainContent\HtmlRenderer::prepare齻齱麀齷齳龪鹾鹼黲
$main_content['#cache_properties'][] = '#title';
齷龋鹴鹳龸龴龲龰龪'#title'鹯龔鼷龮齾龂
黅齷鹮鹬麗黥黤龪鼱齄龆$main_content['#cache_properties'][]麬麪龪鼵鼱鹯龔鹩鼱鼾齟齞齜齘龪鹧
龋鹦鹥黂鹢齜齘龪'#markup'鼞鼝龢齞齜齘鼷鼣龄鹞'#markup'鹯龔鹜黣龪麚
鹚鹖鹒鹐鹍黭黲Drupal\Core\Render::getCacheableRenderArray鹆鹼

麿麼齓齏鹴鹾$elements['#cache']['bin']鹄麪鹁龸龴龊龆龲龰龪齾龂鸿鸾龢鼷齓齏鼵麬麪
鼵麬麪鸻黂鸺黲$elements['#cache']['bin']='render'龢鸹齏齾龂鼪鼦龮龄龂龁龲鸸鸷龪'render'齾龂鸴鹮

麗鸰鸬齾龂麀鸪齟鸩麗鸨鸦龢鸢龦鸞鸛齱鼱鸗鸓鸨鸦黲
$elements['#cache']['max-age']鼵鸊鸺0
$elements['#cache']['keys']鸩鸆麗龮鸅鸾
齀鸪鸨鸦鼣麗麀鼾齟鼵鸃齈齱鼵龌龮齾龂龢齄龆齗鸃齈齱鼾麪龌龮齾龂鸂

龸龴龲龰龪龸龴鼲鷿齻$elements['#cache']['keys']鼱鼵鷼鷺鷹鼫龪
黣鹜龸龴龲龰龪$elements['#cache']['contexts']鷷鸢鷳麪龞齾龂id黰Cid)
鷮麱齷鹮齱鷪鹐龞鼾齟鷩鷨黲龸龴鹢鷧鸸黂龦龪鸨鸦齓鷥鷤鷪龪Cid鹜龸龴鷣鷥鷤鷪龪Cid齓龐鼱鼵鸢龪
龠龞鷢鷞鹆鷜龢齷鹮龋龸龴鹢齓鷥鷤鷪龪Cid鼙鼘鼕龸龴鹢Cid",龋龸龴鷣齓鷥鷤鷪龪Cid鼙鼘鼕龸龴鷣Cid"
龸龴鷒鷏龦齞齜齘龪齾龂黉鼟鷎鷌鷉鷅鷁黉鼺龢鷀鶿鶼鸺#lazy_builder鷌鷉鶷鶳龢鼷齓龐龮鼾鶲鶱鶭鸊鶩鶨
鸹齏麏龸龴鷒鶦齦鼵鶥鶤龸龴鷣龪齾龂黉鼟鷎龢鼷齱鼵鶥鶤龸龴鷣Cid龢齄齀鼾鼺齱鶣麀鶠鹼鶟鶱齾龂龪龲鸸

鷮麲麱鶝鷳鶙麭drupal鹴鹾龞鶗齫齾龂黰Two-tier caching黦龢鶎鼙鼘齾龂齫麪鶍鶋鶉龢鹚鹖齄鼟黲
龸龴鶈鸃鷣龄龂齾龂龲鸸龦龢鶆鶅齾龂黉鼟鷎鼱鶄麀鷹鼫龢齄龆鶣麀鷹鼫龢鷮麱龸龴鹢鷣龪Cid鼱鼾齳龪龢鶣麀鶂麱鷩鷨龢鶀鵽龋龲鸸龄龂龁齷齟cid鼟麓齓
齄龆麀鷹鼫龢鵼鷥鷤鷪龸龴鷣龪齾龂齜龲鸸龲龰龢麶齻黢鵹'keys'鹜'bin'
齀鵵鵴鵳鼾齟'#cache_redirect'鹯龔龢麶麚鼵龠NULL龢鼪鼦鸅鸾龠true
鵪鷣龋齷齟龸龴鷣龪齾龂齜龲鸸龲龰黰黥黤鼵鼱龸龴鷣龪龲龰黦龄龂龁龸龴鹢Cid鼟龢鵨鸃鼾齟齫麪鶍齾龂
齷齟齫麪鶍齾龂鵥鵤龪tags鵢max-age鹜龸龴鷣龪齾龂齜龲鸸鼾鵠
麏鵞鶟齾龂龲鸸龦龢齄龆鵚鹐鸅鸾龞'#cache_redirect'鵼鵖鵕鼱鼾齟齫麪鶍齾龂龢鷮麱鵓鼲鹳龁龪龲鸸鵐鵍get齾龂龢鼯鼲鸪鵊齾龂鵆鵂鹳龁龸龴鷣鼞鼝

思考:

龐鶄龋龸龴鷣龪龊龆鶀鵽龄龂麏龸龴鹢Cid鼟鶙麭龠鶂麱麭
齄龆齷齳鼘龢鷮麱麏鴿鴾麶黣鴺鹆麗鴹齷鴵齾龂鸰鸬鴱鴰龦龢鷮麱齱鹬麗鶥鶤黣龸龴鹢龪Cid龢齷齓龐鼱齟鷩鷨
齾龂API龪鼾鴬鴩鵼鼱黲龮齾龂龪龲鸸鴹鴨鹄鴥齾龂鹯龔龲鸸龢齓齏鴡龸龴鷣龪龸龴龲龰鹄鵤鷥鷤鷪鴹鴠龪齾龂id

齾龂齫麪鶍龪鼕鴜鴚鴘鷩鷨黳黲
鴔鴒麀齷齳鼾齟龸龴龲龰黲

- A (#cache['keys'] = ['foo'])   
-- B (#cache['contexts'] = ['b'])  
--- C (#cache['contexts'] = ['c'])  
--- D (#cache['contexts'] = ['d'])  

麏A鵊鴉麀鶣麀麬麪黉鼟鷎鴹齷齟鷩鷨鶣麀鴆鴅龢齷鹮鴂麪鶣麀麬麪黉鼟鷎
B鼱A龪齞齜齘龢C鵢D鼱B龪齞齜齘龢黅C鵢D鼣龐鷧鸸B龪黉鼟鷎麚龢鴁鳽鼾龪龂麏鼾齟
鹚鹖鳺齱鼱黲B龪黉鼟鷎'b' = 'b1'龦鳳麀齞齜齘C龢'b' = 'b2'龦鳳麀齞齜齘D
齀龦鳭齟龸龴龲龰龪龊龆鶟鷳鸺B鵊鴉麬麪龪黉鼟鷎b龪麚龢黉鼟鷎b鹜齜齘龪鴹鴠鳩鴿鸃龠鼾齟鳥鸾鳤龢鳢鳥鸾鳤鸃龠鳞鳜鴆鴅龁鳭齟A龪麀鳚龔
麏齷齳龪鳖鳕鼟鳓鳓齾龂齫麪鶍龌鵚鳑鶂麱黲
黂'b' = 'b1'龦黲A龪龸龴鹢Cid龠鼕foo黳 鼞鼝麬鶍bc
黂'b' = 'b2'龦黲A龪龸龴鹢Cid龠鼕foo黳 鼞鼝麬鶍bd
鸪齟鳎鳌龪鼵鸢鼞鼝龸龴龲龰龪龸龴鹢Cid鳈鳇龞龢齄龆麏龸龴龲龰齻鼵鳅鵳鳃鵵龪鳞鳜鼺鹖鹐黣麼龪黨鳀鷹鼫龢齷鹮龋鴡齾龂鶟鶱鲼鲺龪龲鸸
齄龆鳅鸦鳞鳜龲鸸龢麐齄齷鹮齄龆鸅鸾黉鼟鷎b鹜鳥鸾鳤鸃龠鳞鳜龢麴麼龌鲹鲸鲵鲱齾龂麀鳚龔龢鸹齏鶟鶱鼺龪龲鸸鼵龌麀鲼
黅鼱麏齷齳龪鳖鳕鼟龢鲰鵪鶣麀鲼龢黅齾龂鲬黅鶣麀鲩鲧鷥鷤龢鲣鸃龠龞鲡鲟龢麏b龪鼵鸢黉鼟鷎鳎鳌齻龌鼵鲝鸅鸾齾龂
齱鲛鼱麏鲚齻龪鲖鲓鲏齷鲌龢鷮鲌鲋鲊龢鲓鲏鷮鲌龦齷鲌鶎鲋鲊龢鷀鲛鴜鴚鴘鸪鲉鲈龢齷齱鼱鳢鷩鷨麖鲇龪鶼鼺
龠龞鶝鷳齷齟鷩鷨龢鴿鴾鹒鹐龞鼾鲃鹆鹼龢齯齭鲀鱼龪鴹龸龴鹢cid龪鼞鼝鸰鸬鶩鶨龢鼣鶩鶨龸龴鷣Cid龪鼞鼝
齱鼱鱺龸龴鹢Cid麏鱸鳎鳌鱶鱲鱰鱯鱭鸹麀龪黉鼟鷎龢鵆鵂龄龂鸹麀龪黉鼟鷎龢鵨鸃鼾齟鱫麪麬鶍
麬鶍龪鼞鼝齱鼱龸龴鷣Cid龪鼞鼝龢齷齟鼞鼝鼱龌鲀鱼鸅鸾龪龢鵓鼲鳞鳜鼺龄鱨鱧鲸龔

鷺鱤鱢鷿鱟鶭鱞麏鷥鷤鱛鱗鱔齻麀鸪鸦鱓鳖麐鱏鱌鱋黲齾龂鹜鱇麖
齄龆鱃鼵龐麮鶝黉鱀龪鼞鼝龢齓齏鰼鰻鼟龢麏鷣鱀麀鹚鹖龸龴龲龰龪鰷齞鷣鰵鶱鼲鲌鼺鳓龢鰳鰳鹖龌齾龂黉鼟鷎鹜鳞鳜鰯鱶龪鰫鰧鳩鴿
麏鹄麪鹁龪龸龴龲龰齻麗鰣鳀黥黤黉鷞鴜鴚鴘鷩鷨鰡鲊龪鰠麏鲼鲺

占位渲染缓存:

麏drupal鹒鰝龪鹴鹾齻龢龸龴齾龂鰛鹾龪鼱鰙鸿龸龴齾龂PlaceholderingRenderCache黣鰕鸗龞RenderCache龪鰑龐
麿麼鶥鶤龸龴鰙鸿鰐龪鰏龪齱鼱龋鴿鴾鼵鰍鰉齾龂龪鼞鼝齌齈鷪鼺龢鰇齌龸龴龢龊龆齦鼵龌齾龂
鷮麱麏鼾齟鰆鱀齻齷齳龪鼞鼝鷪鹐鱤鰂龢鶼鸺鶣麀齾龂龢鸹齏鹬麗鱤鰂龸龴龢齷鼱鶣麀鸩麗龪
鸹齏龠龞鶝鷳齷齟鷩鷨龢鰁鶳龞鼕鰙鸿龸龴齾龂PlaceholderingRenderCache黳龢麏齷齟龸龴齾龂齻
龋鼵鰍鰉齾龂龪鼞鼝龄龂麏鯾龪鹯龔齻龢鱤鰂鹬麗龦龢鶀鵽鯼鶱龢龋鼵龌鰵鰂龸龴龢齷齱龛龘龞龔龐
鴔鴒黲龠鶂麱鼵鯻鸹麀鴡齾龂鶟鶱龪龲鸸齗鸰鸬齷齳龪麯麮鶙麭齷齳齯齭鱤鰂鶭鹾齾龂龢鯸鯷龲鸸鸷鯵鯱鼵鼱鯭龘鳚鯪麭
麗麮鶝龠鶂麱鴿鴾鶣麀齷齳鼘鹬麗鵕鯨鰙鸿鰐齜齘龪龸龴鼱麏龸龴鵆鷣鸰鸬龪龢鹩麶麴鼵鼱
齄龆齷齳麯麮龢黂鴿鴾鯧鷿鰡鲊鳞鳜鷹鼫龢齾龂鯦鳚龢齷齳齱龌鯥鳑鲼鲺
鹩鰙鸿龸龴齜齘龠鶂麱鼵鯡鯞龲鸸鷹鼫龪鷩鷨龢鯚龠麏鴿鴾鵆鷣鯖鸬鰙鸿鯔鯑龦龢麴麼鼱鯎麏鼾鲊鯖鸬龪龢鶣麀麶麴鯧鷿鯊鯇麶齻

本书共63小节:

评论 (写第一个评论)