mirror of
https://github.com/eryajf/chatgpt-dingtalk.git
synced 2025-10-18 06:00:41 +08:00
feat: add user request limit config (#98)
This commit is contained in:
22
pkg/cache/user_context.go
vendored
Normal file
22
pkg/cache/user_context.go
vendored
Normal 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")
|
||||
}
|
Reference in New Issue
Block a user