[Upstream] fix: invalidate group_models Redis cache on channel create/update/delete#124
Open
Sagit-chu wants to merge 1 commit into
Open
[Upstream] fix: invalidate group_models Redis cache on channel create/update/delete#124Sagit-chu wants to merge 1 commit into
Sagit-chu wants to merge 1 commit into
Conversation
…delete (fixes songquanpeng#2327) When a channel is created, updated, or its status changed, the Redis group_models:{group} cache was not invalidated. This meant users had to wait up to SYNC_FREQUENCY seconds (default 10 min) before newly added channel models appeared in the token model-scope selector. Add ClearGroupModelsCacheByGroups to model/cache.go and call it from AddAbilities, DeleteAbilities (which UpdateAbilities delegates to), and UpdateChannelStatusById so the stale cache entry is evicted immediately after each change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Synced from upstream PR: songquanpeng#2381
Fixes songquanpeng#2327
Problem
When a channel is created, updated, or its enabled/disabled status is changed, the Redis
group_models:{group}cache key is not invalidated. Because this cache has a TTL equal toSYNC_FREQUENCY(default 10 minutes), users who create a new channel must wait up to 10 minutes before the channel's models appear in the token model-scope selector (/api/user/available_models). During this time, searching for the newly added model (e.g.gemini-2.5-pro) returns no results in the dropdown.Solution
Add
ClearGroupModelsCacheByGroups(groups []string)tomodel/cache.gothat deletes the relevant Redis keys for the affected groups. Call it:AddAbilities()after successfully inserting ability rows (channel create)DeleteAbilities()after successfully deleting ability rows (channel delete / update)UpdateChannelStatusById()after changing channel status (channel enable/disable)UpdateAbilities()already delegates toDeleteAbilities+AddAbilities, so channel updates are covered automatically.No-op when Redis is not enabled.
Testing
/api/user/available_models— with the fix the new model appears immediately; without it the old cache is still returned.go build ./...succeeds.