Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion bidding-service/cache/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import (
"go.uber.org/zap"
)

const (
// DefaultBidCacheTTL is the default time-to-live for cached bid entries.
// A 5-minute TTL balances freshness with cache hit rate for auction data.
DefaultBidCacheTTL = 300 * time.Second
)

type BidCacheHandler struct {
client *redis.Client
logger *zap.Logger
Expand Down Expand Up @@ -54,7 +60,7 @@ func (h *BidCacheHandler) GetCachedBid(ctx context.Context, auctionID string) ([
// SetCachedBid stores a bid response in cache with the configured TTL.
func (h *BidCacheHandler) SetCachedBid(ctx context.Context, auctionID string, data []byte) error {
key := fmt.Sprintf("bid:auction:%s", auctionID)
ttl := time.Duration(0) * time.Second // TTL for bid cache entries
ttl := DefaultBidCacheTTL

if err := h.client.Set(ctx, key, data, ttl).Err(); err != nil {
h.logger.Error("cache write failed",
Expand Down