Skip to content

Latest commit

 

History

History
53 lines (44 loc) · 2.04 KB

File metadata and controls

53 lines (44 loc) · 2.04 KB

Cache-As-SOR

Motivation

Solution

Concepts

Sub-Patterns

Pattern Name Diagram Description
Read-Through If requested data is not in cache, cache will load the data from database and let application read synchronously.
Write-Through After application writes data to cache, cache synchronously writes the same data to database.
Write-Behind After application writes data to cache, cache asynchronously writes the same data to database (When satisfy a certain criteria).
Refresh-Ahead Cache automatically and asynchronously reloads (refreshs) any recently accessed cache entry from database before its expiration.

Implementation

Pros & Cons

  • Write-Through
    • Pros
      • No risk of data loss.
    • Cons
      • Slow (cache can only ack back until writing data to database successfully).
      • When a new cache node is added, the new cache node will be empty until there is a update from the application.
  • Write-Behind
    • Pros
      • Faster (cache can ack back without writing data to database).
    • Cons
      • Risk of data loss: Data may lose after cache goes down, but before it have been written to database.
      • More complex to implement.
  • Refresh-ahead
    • Pros
      • Faster
    • Cons
      • Not accurately predicting which items are likely to be needed in the future can result in reduced performance than without refresh-ahead.

Consideration

Topic Consideration Possible Solution Options

When To Use

References