參考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ú)法找回唉擂。