Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coupon APIをキャッシュする #204

Merged
merged 1 commit into from
Oct 25, 2024
Merged

coupon APIをキャッシュする #204

merged 1 commit into from
Oct 25, 2024

Conversation

hekki
Copy link
Member

@hekki hekki commented Oct 25, 2024

背景・設計

#202 と同様となります。

動作確認

golangのデバッグモードで動作確認をしました。

1. プロセス起動直後に /metrics にHTTPアクセス

  • キャッシュが存在しないことを確認
スクリーンショット 2024-10-25 16 09 08
  • coupon APにリクエストが行われたことを確認
  • メトリクスが正しく取得できることを確認

2. 再度 /metrics にHTTPアクセス

  • キャッシュが存在することを確認
スクリーンショット 2024-10-25 16 09 48
  • coupon APにリクエストが行われないことを確認
  • メトリクスが正しく取得できることを確認

// Billing APIは1日1回 AM4:30 (JST) にデータが更新される。
// このため、現在時刻がAM4:30 (JST) よりも早ければ当日のAM4:30 (JST)、
// 現在時刻がAM4:30 (JST) よりも遅ければ翌日のAM4:30 (JST) を有効期限として扱う。
func (c *couponClient) nextCacheExpiresAt() (time.Time, error) {
Copy link
Member Author

@hekki hekki Oct 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

platform/bill.go とロジックが重複してしまっていますが、キャッシュの有効期限はキャッシュを使う側が決定するほうが自然と考えたので、こちらに実装しています。

@hekki hekki marked this pull request as ready for review October 25, 2024 07:15
@hekki hekki requested a review from yamamoto-febc October 25, 2024 07:15
Copy link
Member

@yamamoto-febc yamamoto-febc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@hekki hekki merged commit 6c9b525 into master Oct 25, 2024
13 checks passed
@hekki hekki deleted the cahce-coupon branch October 25, 2024 07:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants