feat: add cache shenanigan
parent
14507f86d8
commit
286d21a723
|
@ -0,0 +1,83 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.2.0/github-markdown-dark.min.css"
|
||||
/>
|
||||
<title>haunt98 posts</title>
|
||||
</head>
|
||||
<style>
|
||||
.markdown-body {
|
||||
box-sizing: border-box;
|
||||
min-width: 200px;
|
||||
max-width: 980px;
|
||||
margin: 0 auto;
|
||||
padding: 45px;
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
.markdown-body {
|
||||
padding: 15px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<body class="markdown-body">
|
||||
<div><a href="index.html">Index</a></div>
|
||||
<h1>
|
||||
<a
|
||||
id="user-content-cache-shenanigan"
|
||||
class="anchor"
|
||||
aria-hidden="true"
|
||||
href="#cache-shenanigan"
|
||||
><span aria-hidden="true" class="octicon octicon-link"></span></a
|
||||
>Cache shenanigan
|
||||
</h1>
|
||||
<p>
|
||||
My notes/mistakes/... when using cache (mainly Redis) from time to time
|
||||
</p>
|
||||
<p>My default strategy is:</p>
|
||||
<ul>
|
||||
<li>Write to database first then to cache second</li>
|
||||
<li>
|
||||
Read from cache first, if not found then read from database second, then
|
||||
re-write to cache
|
||||
</li>
|
||||
</ul>
|
||||
<p>It's good for general cases, for example with CRUD action.</p>
|
||||
<p>
|
||||
The bad things happen when cache and database are not consistent. For
|
||||
example what happen if writing database OK then writing cache failed? Now
|
||||
database has new value, but cache has old value Then when we read again,
|
||||
we read cache first with old value, and that is disaster.
|
||||
</p>
|
||||
<h2>
|
||||
<a
|
||||
id="user-content-thanks"
|
||||
class="anchor"
|
||||
aria-hidden="true"
|
||||
href="#thanks"
|
||||
><span aria-hidden="true" class="octicon octicon-link"></span></a
|
||||
>Thanks
|
||||
</h2>
|
||||
<ul>
|
||||
<li>
|
||||
<a
|
||||
href="https://danielw.cn/cache-consistency-with-database"
|
||||
rel="nofollow"
|
||||
>Cache Consistency with Database</a
|
||||
>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div>
|
||||
Feel free to ask me via
|
||||
<a href="mailto:hauvipapro+posts@gmail.com">email</a> or
|
||||
<a rel="me" href="https://hachyderm.io/@haunguyen">Mastodon</a>. Source
|
||||
code is available on
|
||||
<a href="https://github.com/haunt98/posts-go">GitHub</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -61,6 +61,7 @@
|
|||
<li><a href="2023-06-25-useful-tools.html">Useful tools</a></li>
|
||||
<li><a href="2023-07-01-pastebin.html">Pastebin</a></li>
|
||||
<li><a href="2023-07-02-fandroid.html">F(an) android</a></li>
|
||||
<li><a href="2023-07-30-cache-shenanigan.html">Cache shenanigan</a></li>
|
||||
</ul>
|
||||
|
||||
<div>
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
# Cache shenanigan
|
||||
|
||||
My notes/mistakes/... when using cache (mainly Redis) from time to time
|
||||
|
||||
My default strategy is:
|
||||
|
||||
- Write to database first then to cache second
|
||||
- Read from cache first, if not found then read from database second, then re-write to cache
|
||||
|
||||
It's good for general cases, for example with CRUD action.
|
||||
|
||||
The bad things happen when cache and database are not consistent.
|
||||
For example what happen if writing database OK then writing cache failed?
|
||||
Now database has new value, but cache has old value
|
||||
Then when we read again, we read cache first with old value, and that is disaster.
|
||||
|
||||
## Thanks
|
||||
|
||||
- [Cache Consistency with Database](https://danielw.cn/cache-consistency-with-database)
|
|
@ -27,3 +27,4 @@ This is where I dump my thoughts.
|
|||
- [Useful tools](2023-06-25-useful-tools.html)
|
||||
- [Pastebin](2023-07-01-pastebin.html)
|
||||
- [F(an) android](2023-07-02-fandroid.html)
|
||||
- [Cache shenanigan](2023-07-30-cache-shenanigan.html)
|
||||
|
|
Loading…
Reference in New Issue