一、写命中场景
Write-through- Write is done synchronously both to the cache and to the backing store. (维基百科定义)
翻译:Write-through(直写模式)在数据更新时,同时写入缓存Cache和后端存储。此模式的优点是操作简单;缺点是因为数据修改需要同时写入存储,数据写入速度较慢。
试用场景,读多写好,相对来说写时延在整个业务场景下占比不大。
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-back(回写模式)在数据更新时只写入缓存Cache。只在数据被替换出缓存时,被修改的缓存数据才会被写到后端存储。此模式的优点是数据写入速度快,因为不需要写存储;缺点是一旦更新后的数据未被写入存储时出现系统掉电的情况,数据将无法找回。
试用场景,写多,或者读写平均的场景。
二、写不命中场景
Write allocate (also called fetch on write): data at the missed-write location is loaded to cache, followed by a write-hit operation. In this approach, write misses are similar to read misses.。Write allocate:先把要写的数据载入到Cache中,写Cache,然后再通过flush方式写入到内存中; 写缺失操作与读缺失操作类似。
No-write allocate (also called write-no-allocate or write around): data at the missed-write location is not loaded to cache, and is written directly to the backing store. In this approach, only the reads are being cached。No write allocate:并不将写入位置读入缓存,直接把要写的数据写入到内存中。这种方式下,只有读操作会被缓存
三、维基百科流程图
(一) write allocate
(二) no-write allocate