From ba21a870cd1845f0f4499cc6df475ed09953ecf9 Mon Sep 17 00:00:00 2001 From: fengsilin Date: Tue, 24 Mar 2026 11:30:09 +0800 Subject: [PATCH] feat: invalidate cache on channel pricing changes Co-Authored-By: Claude Opus 4.6 --- model/channel_pricing.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/model/channel_pricing.go b/model/channel_pricing.go index dbb0a11..721d95e 100644 --- a/model/channel_pricing.go +++ b/model/channel_pricing.go @@ -44,12 +44,16 @@ func (cp *ChannelPricing) Insert() error { now := common.GetTimestamp() cp.CreatedTime = now cp.UpdatedTime = now - return DB.Create(cp).Error + err := DB.Create(cp).Error + if err == nil { + InvalidateChannelPricingCache() + } + return err } func (cp *ChannelPricing) Update() error { cp.UpdatedTime = common.GetTimestamp() - return DB.Model(&ChannelPricing{}).Where("id = ?", cp.Id).Updates(map[string]interface{}{ + err := DB.Model(&ChannelPricing{}).Where("id = ?", cp.Id).Updates(map[string]interface{}{ "quota_type": cp.QuotaType, "model_ratio": cp.ModelRatio, "completion_ratio": cp.CompletionRatio, @@ -57,10 +61,18 @@ func (cp *ChannelPricing) Update() error { "tag_ids": cp.TagIds, "updated_time": cp.UpdatedTime, }).Error + if err == nil { + InvalidateChannelPricingCache() + } + return err } func (cp *ChannelPricing) Delete() error { - return DB.Delete(cp).Error + err := DB.Delete(cp).Error + if err == nil { + InvalidateChannelPricingCache() + } + return err } // GetChannelPricing 获取指定模型在指定渠道的定价