user_base.go 986 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package cache
  2. import (
  3. "time"
  4. "github.com/patrickmn/go-cache"
  5. )
  6. // UserServiceInterface 用户业务接口
  7. type UserServiceInterface interface {
  8. // 用户聊天模式
  9. GetUserMode(userId string) string
  10. SetUserMode(userId, mode string)
  11. ClearUserMode(userId string)
  12. // 用户聊天上下文
  13. GetUserSessionContext(userId string) string
  14. SetUserSessionContext(userId, content string)
  15. ClearUserSessionContext(userId string)
  16. // 用户请求次数
  17. SetUseRequestCount(userId string, current int)
  18. GetUseRequestCount(uerId string) int
  19. // 用户对话ID
  20. SetAnswerID(userId, chattype string, current uint)
  21. GetAnswerID(uerId, chattype string) uint
  22. ClearAnswerID(userId, chattitle string)
  23. }
  24. var _ UserServiceInterface = (*UserService)(nil)
  25. // UserService 用戶业务
  26. type UserService struct {
  27. // 缓存
  28. cache *cache.Cache
  29. }
  30. // NewUserService 创建新的业务层
  31. func NewUserService() UserServiceInterface {
  32. return &UserService{cache: cache.New(time.Hour*2, time.Hour*5)}
  33. }