From 286d21a72359f1243f9cf5c060c15c1cc4b8a49b Mon Sep 17 00:00:00 2001 From: Hau Nguyen Date: Sun, 30 Jul 2023 11:42:20 +0700 Subject: [PATCH] feat: add cache shenanigan --- docs/2023-07-30-cache-shenanigan.html | 83 +++++++++++++++++++++++++++ docs/index.html | 1 + posts/2023-07-30-cache-shenanigan.md | 19 ++++++ posts/index.md | 1 + 4 files changed, 104 insertions(+) create mode 100644 docs/2023-07-30-cache-shenanigan.html create mode 100644 posts/2023-07-30-cache-shenanigan.md diff --git a/docs/2023-07-30-cache-shenanigan.html b/docs/2023-07-30-cache-shenanigan.html new file mode 100644 index 0000000..69c3cd8 --- /dev/null +++ b/docs/2023-07-30-cache-shenanigan.html @@ -0,0 +1,83 @@ + + + + + + + haunt98 posts + + + +
Index
+

+ Cache shenanigan +

+

+ My notes/mistakes/... when using cache (mainly Redis) from time to time +

+

My default strategy is:

+ +

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 +

+ + +
+ Feel free to ask me via + email or + Mastodon. Source + code is available on + GitHub +
+ + diff --git a/docs/index.html b/docs/index.html index 42176bd..e72e121 100644 --- a/docs/index.html +++ b/docs/index.html @@ -61,6 +61,7 @@
  • Useful tools
  • Pastebin
  • F(an) android
  • +
  • Cache shenanigan
  • diff --git a/posts/2023-07-30-cache-shenanigan.md b/posts/2023-07-30-cache-shenanigan.md new file mode 100644 index 0000000..3d85b1c --- /dev/null +++ b/posts/2023-07-30-cache-shenanigan.md @@ -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) diff --git a/posts/index.md b/posts/index.md index 5e94ecf..c6aab46 100644 --- a/posts/index.md +++ b/posts/index.md @@ -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)