Skip to content

Commit

Permalink
add comments about awaiting the redis write
Browse files Browse the repository at this point in the history
  • Loading branch information
warriordog committed Aug 17, 2024
1 parent aeb1d34 commit 5a1ef8d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/backend/src/misc/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ export class RedisKVCache<T> {

/**
* キャッシγƒ₯γŒγ‚γ‚Œγ°γγ‚Œγ‚’θΏ”γ—γ€η„‘γ‘γ‚Œγ°fetcherγ‚’ε‘Όγ³ε‡Ίγ—γ¦η΅ζžœγ‚’γ‚­γƒ£γƒƒγ‚·γƒ₯&返します
* This awaits the call to Redis to ensure that the write succeeded, which is important for a few reasons:
* * Other code uses this to synchronize changes between worker processes. A failed write can internally de-sync the cluster.
* * Without an `await`, consecutive calls could race. An unlucky race could result in the older write overwriting the newer value.
* * Not awaiting here makes the entire cache non-consistent. The prevents many possible uses.
*/
@bindThis
public async fetch(key: string): Promise<T> {
Expand Down Expand Up @@ -172,6 +176,10 @@ export class RedisSingleCache<T> {

/**
* キャッシγƒ₯γŒγ‚γ‚Œγ°γγ‚Œγ‚’θΏ”γ—γ€η„‘γ‘γ‚Œγ°fetcherγ‚’ε‘Όγ³ε‡Ίγ—γ¦η΅ζžœγ‚’γ‚­γƒ£γƒƒγ‚·γƒ₯&返します
* This awaits the call to Redis to ensure that the write succeeded, which is important for a few reasons:
* * Other code uses this to synchronize changes between worker processes. A failed write can internally de-sync the cluster.
* * Without an `await`, consecutive calls could race. An unlucky race could result in the older write overwriting the newer value.
* * Not awaiting here makes the entire cache non-consistent. The prevents many possible uses.
*/
@bindThis
public async fetch(): Promise<T> {
Expand Down

0 comments on commit 5a1ef8d

Please sign in to comment.