Upgrade to Pro — share decks privately, control downloads, hide ads and more …

GoのGenericsを使った効率的なキャッシュの実装 / Effective Generic Cache in Golang

motoki317
December 23, 2023

GoのGenericsを使った効率的なキャッシュの実装 / Effective Generic Cache in Golang

motoki317

December 23, 2023
Tweet

Other Decks in Programming

Transcript

  1. @toki traP所属 一般学生Gopher • ISUCON11本選作問 • ISUCON10, 12, 13 準優勝

    近況 • ISUCON13でNaruseJunにまた負けた • traP部内向けPaaS「NeoShowcase」を作った motoki317 motoki1_
  2. GoのGenerics (since 1.18, 2022-03-15) Genericsが実装されて久しい Goのサポート対象は最新 2 minor versions 現在

    (as of 2023-12-23) は 1.20, 1.21 Goは後方互換性が強い → Genericsは既に問題なく導入できる [2] https://github.com/tottie000/GopherIllustrations 嬉しそうな Gohperくん [2]
  3. インターフェイス設計 (2/2) 設定にFunctional Options Pattern 破壊的な変更を避け、 機能追加を行いやすい Genericな設定を取りたい場合は 相性が悪いかも 出来なくは無いが、類推が弱い

    [4] command center: Self-referential functions and the design of options, https://commandcenter.blogspot.com/2014/01/self-referential-functions-and-design.html Functional Options Pattern [4]
  4. ttl = 0 かつ sc.EnableStrictCoalescing() で利用可能 Zero Time Cache [7]

    [7] https://qiita.com/methane/items/27ccaee5b989fb5fca72
  5. ttl = 0 かつ sc.EnableStrictCoalescing() で利用可能 Zero Time Cache [7]

    [7] https://qiita.com/methane/items/27ccaee5b989fb5fca72
  6. ttl = 0 かつ sc.EnableStrictCoalescing() で利用可能 Zero Time Cache [7]

    [7] https://qiita.com/methane/items/27ccaee5b989fb5fca72
  7. ttl = 0 かつ sc.EnableStrictCoalescing() で利用可能 Zero Time Cache [7]

    BのGet開始前の結果 BにとってStale [7] https://qiita.com/methane/items/27ccaee5b989fb5fca72
  8. ttl = 0 かつ sc.EnableStrictCoalescing() で利用可能 Zero Time Cache [7]

    BのGet開始前の結果 BにとってStale Aが返り次第、 ZTCは次のSELECTを開始 [7] https://qiita.com/methane/items/27ccaee5b989fb5fca72
  9. ttl = 0 かつ sc.EnableStrictCoalescing() で利用可能 Zero Time Cache [7]

    BのGet開始前の結果 BにとってStale Aが返り次第、 ZTCは次のSELECTを開始 BのGet開始後の結果 BにとってFresh Bで更新後の結果が返る [7] https://qiita.com/methane/items/27ccaee5b989fb5fca72
  10. ttl = 0 かつ sc.EnableStrictCoalescing() で利用可能 Zero Time Cache [7]

    BのGet開始前の結果 BにとってStale Aが返り次第、 ZTCは次のSELECTを開始 BのGet開始後の結果 BにとってFresh Bで更新後の結果が返る ポイント: 「即時反映」は 0秒以上前の結果 を許可しない = リクエスト前開始の SELECT結果を利用できない [7] https://qiita.com/methane/items/27ccaee5b989fb5fca72
  11. ttl = 任意 更新時に Forget() で利用可能 Illust: https://github.com/tottie000/GopherIllustrations 明示的なInvalidate 更新時に

    Forget() を呼ぶことで 以降の Get() は値を再利用せず 直ちにSELECTが飛ぶ 前回のSELECTを無視して 直ちにSELECTが飛ぶ
  12. ttl = 任意 更新時に Forget() で利用可能 Illust: https://github.com/tottie000/GopherIllustrations 明示的なInvalidate 更新時に

    Forget() を呼ぶことで 以降の Get() は値を再利用せず 直ちにSELECTが飛ぶ 前回のSELECTを無視して 直ちにSELECTが飛ぶ Bで更新後の結果が返る
  13. ttl = 任意 更新時に Forget() で利用可能 Illust: https://github.com/tottie000/GopherIllustrations 明示的なInvalidate 更新時に

    Forget() を呼ぶことで 以降の Get() は値を再利用せず 直ちにSELECTが飛ぶ 前回のSELECTを無視して 直ちにSELECTが飛ぶ Bで更新後の結果が返る ポイント: 「即時反映」は 0秒以上前の結果 を許可しない = リクエスト前開始の SELECT結果を利用できない