參考http://en.wikipedia.org/wiki/Cache#Writing_Policies上的說(shuō)明,Cache寫(xiě)機(jī)制分為write through和write back兩種焚刚。
Write-through- Write is done synchronously both to the cache and to the backing store.
Write-back (or Write-behind) - Writing is done only to the cache. A modified cache block is written back to the store, just before it is replaced.
Write-through(直寫(xiě)模式)在數(shù)據(jù)更新時(shí),同時(shí)寫(xiě)入緩存Cache和后端存儲(chǔ)盐碱。此模式的優(yōu)點(diǎn)是操作簡(jiǎn)單;缺點(diǎn)是因?yàn)閿?shù)據(jù)修改需要同時(shí)寫(xiě)入存儲(chǔ)沪伙,數(shù)據(jù)寫(xiě)入速度較慢瓮顽。
Write-back(回寫(xiě)模式)在數(shù)據(jù)更新時(shí)只寫(xiě)入緩存Cache。只在數(shù)據(jù)被替換出緩存時(shí)围橡,被修改的緩存數(shù)據(jù)才會(huì)被寫(xiě)到后端存儲(chǔ)趣倾。此模式的優(yōu)點(diǎn)是數(shù)據(jù)寫(xiě)入速度快,因?yàn)椴恍枰獙?xiě)存儲(chǔ)某饰;缺點(diǎn)是一旦更新后的數(shù)據(jù)未被寫(xiě)入存儲(chǔ)時(shí)出現(xiàn)系統(tǒng)掉電的情況,數(shù)據(jù)將無(wú)法找回善绎。