feat: add user request limit config (#98)

This commit is contained in:
二丫讲梵
2023-03-17 10:13:13 +08:00
committed by GitHub
parent da654643a7
commit 1686748869
14 changed files with 333 additions and 251 deletions

22
pkg/cache/user_context.go vendored Normal file
View File

@@ -0,0 +1,22 @@
package cache
import "github.com/patrickmn/go-cache"
// SetUserSessionContext 设置用户会话上下文文本question用户提问内容GTP回复内容
func (s *UserService) SetUserSessionContext(userId string, content string) {
s.cache.Set(userId+"_content", content, cache.DefaultExpiration)
}
// GetUserSessionContext 获取用户会话上下文文本
func (s *UserService) GetUserSessionContext(userId string) string {
sessionContext, ok := s.cache.Get(userId + "_content")
if !ok {
return ""
}
return sessionContext.(string)
}
// ClearUserSessionContext 清空GTP上下文接收文本中包含 SessionClearToken
func (s *UserService) ClearUserSessionContext(userId string) {
s.cache.Delete(userId + "_content")
}