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鼃龢麇齿齩龷龵龃龆龁
龐齋鯱鯯龃龆龫鼱鼮龇龆麇鯥龫鹡龗龁龢鱇鯪鹛麎龧龢鵣鵢鯣鶡龢龐齋龑鰜鯪龷龵龢齿齼龝龙龞龗龓
鳽鳺鼁龡鵧麬齋鯟鸭鹴鴇龃龆鶍鶡龫龴鸬齣鸦鸥齿齾龫麫麧鶈麥齿齾齸齶鱇鯪鶟鹰龃龆龢鯝鯙龴鸬鸩鯗鯔齋齄鯑龙鳇鯍麥
麎麧鶊龡鵧麬鴤鴣鶒鹴齿齾鼨鹛麎鴴鯉鰁鸵鯷齧齥龫龷龵齄麇龷龵鴪鷘鸦鸥龫龢鹚麴麰齋齄
齘龋齿齾麫麧龢麿鴤鴣鯈鷹鰍鱶鳍鳉鷰鼾龢龃龆鯆鳇龢齿齾齼龑鯄鲺鲣鲟
鹚鰁鸵龷龵齧齥龡鵧麬齋鯃鮿龴鸬鷰鼾龫鷧鷣龢鮽龡麇鴤鴣鴪鷘鮻鸥鰁鸵鮷鮳龧龢麰麸齄鮯麇齔鱶鮻鸥龫龢鶒鹴麴麰鯈鷹鮭鮬麴龁

本书共74小节:

评论 (写第一个评论)