Skip to content

Cache Write Policies

Janvi Talreja edited this page Jan 12, 2023 · 4 revisions

Introduction

  • The cache supports both read and write operations.
  • CPU reads from the cache and will write in the cache if there are any changes.
  • There can be multiple cache blocks for a single main memory. Ex CPU in a multiprocessing system.
  • Here comes in Cache write policies. There are three of them - Write around, Write back, Write through.

Problem Statement

When using cache for faster access with a main memory at back, when we write to the cache, we need to write back to the main memory as well. Otherwise, the data between the cache memory and the main memory will be inconsistent.

Variety of Use Cases

A cache’s write policy is the behavior of a cache while performing a write operation. When we want the fast write back then we use a write-back cache.

Features and Properties

Write Around: Here data is Directly written/updated to the main memory without disturbing the cache. It is better to use this when the data is not immediately used again.

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.

Constraints and Limitations

Besides write-back having more difficult implementation, it’s possible to encounter consistency issues. Having cache in volatile memory, power outage before write-back is complete would result in data loss.

Outcome

Based on different use case we choose the cache write strategy.

Clone this wiki locally