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黲龤鹱齻齢龹龷齿龆齾
龏鼻鯨鯦齿龆龬鼡鼝龊龆鹱鯖龬鹏龕齾龤鰯鯛鹉鹻龫龤鵃鵀鯓鶀龤龏鼻龒鰇鯛龹龷龤齻齵龜龙龟龕龔
鳞鳚黰龢鵄麞鼻鯐鸐鹟鳨齿龆鵨鶀龬龳鸏齘鸉鸈齻齸龬麛麗鵡麕齻齸齳齰鰯鯛鵾鹞齿龆龤鯏鯌龳鸏鸎鯊鯆鼻鼷鯂龙鲡鮾麕
鹻麗鵤龢鵄麞鴄鴂鵬鹟齻齸鼘鹉鹻鴔鮻鯲鸙鯭齜齚龬龹龷鼷鹱龹龷鴉鶰鸉鸈龬龤鹅麥麢鼻鼷
齇龋齻齸麛麗龤麳鴄鴂鮺鷕鯼鱜鲦鲥鷎鼮龤齿龆鮶鲡龤齻齸齵龒鮲鲔鲂鱾
鹅鯲鸙龹龷齜齚龢鵄麞鼻鮰鮯龳鸏鷎鼮龬鶿鶼龤鮫龢鹱鴄鴂鴉鶰鮩鸈鯲鸙鮥鮢龫龤麢麬鼷鮟鹱齁鱜鮩鸈龬龤鵬鹟麥麢鮺鷕鮛鮚麥齾

本书共69小节:

评论 (写第一个评论)