a cache is a faster storage on top of a slower storage (backstore) to hopefully speed up future access to the same data;

there are cache policies for both reads and writes;

read policy

a read may either hit or miss the cache;

read-hit policy

trivial; simply return data from the cache;

read-miss policy

  • read-allocate:

    if cache is full, evict a cache item;

    read data from backstore into cache, and return the data;

    read-allocate speeds up future reads on the same data;

  • read-no-allocate:

    read data from backstore and return the data;

    this doesnt help future reads on the same data and is almost never used;

write policy

a write may either hit or miss the cache;

write-hit policy

  • write-back:

    write to cache only, and mark the cache item as dirty;

    write to backstore only when a dirty cache item is being evicted; eviction may happen on read-miss (with read-allocate) and write-miss (with write-allocate);

  • write-through:

    write to both cache and backstore (write-through-cache-into-backstore);

write-miss policy

  • write-allocate:

    if cache is full, evict a cache item;

    read data from backstore into cache, then behave like a write-hit;

  • write-no-allocate:

    write directly to backstore;

pairing

any write-hit policy may be paired with any write-miss policy; however, commonly used pairs are:

  • write-back + write-allocate;

    with write-back policy, write-allocate helps speed up future writes on the same data by loading it into cache;

  • write-through + write-no-allocate;

    with write-through policy, write-allocate doesnt help future writes on the same data: write-through dictates every write is through cache into backstore, so allocating a cache item only adds writing overhead;

    in this case, we prefer the simpler write-no-allocate;

references