You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+35Lines changed: 35 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1312,3 +1312,38 @@ Subsequent reads of data added to cache are fast. Cache-aside is also referred
1312
1312
* Each cache miss results in three trips, which can cause a noticeable delay.
1313
1313
* Data can become stale if it is updated in the database. This issue is mitigated by setting a time-to-live (TTL) which forces an update of the cache entry, or by using write-through.
1314
1314
* When a node fails, it is replaced by a new, empty node, increasing latency.
The application uses the cache as the main data store, reading and writing data to it, while the cache is responsible for reading and writing to the database:
1325
+
1326
+
* Application adds/updates entry in cache
1327
+
* Cache synchronously writes entry to data store
1328
+
* Return
1329
+
1330
+
Application code:
1331
+
1332
+
```
1333
+
set_user(12345, {"foo":"bar"})
1334
+
```
1335
+
1336
+
Cache code:
1337
+
1338
+
```
1339
+
def set_user(user_id, values):
1340
+
user = db.query("UPDATE Users WHERE id = {0}", user_id, values)
1341
+
cache.set(user_id, user)
1342
+
```
1343
+
1344
+
Write-through is a slow overall operation due to the write operation, but subsequent reads of just written data are fast. Users are generally more tolerant of latency when updating data than reading data. Data in the cache is not stale.
1345
+
1346
+
##### Disadvantage(s): write through
1347
+
1348
+
* When a new node is created due to failure or scaling, the new node will not cache entries until the entry is updated in the database. Cache-aside in conjunction with write through can mitigate this issue.
1349
+
* Most data written might never read, which can be minimized with a TTL.
0 commit comments