Fetch the repository succeeded.
package store
import (
"encoding/json"
"time"
"gitee.com/carlmax_my/console-core-go/pkg/cache"
"gitee.com/carlmax_my/console-core-go/pkg/trace"
)
type BaseStore struct {
cache cache.Cache
ttl time.Duration
}
func New(cache cache.Cache) (*BaseStore, error) {
return &BaseStore{
cache: cache,
// ttl: configs.GetLoginSessionTTL(),
}, nil
}
func NewWithTTL(cache cache.Cache, ttl time.Duration) (*BaseStore, error) {
return &BaseStore{
cache: cache,
ttl: ttl,
}, nil
}
func (s *BaseStore) Set(key string, value interface{}, options ...cache.Option) error {
return s.cache.Set(key, value, s.ttl, options...)
}
func (s *BaseStore) SetT(key string, value interface{}, trace trace.T) error {
return s.Set(key, value, cache.WithTrace(trace))
}
func (s *BaseStore) SetModel(key string, value interface{}, options ...cache.Option) error {
if bytes, err := json.Marshal(value); err != nil {
return err
} else {
return s.cache.Set(key, bytes, s.ttl, options...)
}
}
func (s *BaseStore) SetModelT(key string, value interface{}, trace trace.T) error {
return s.SetModel(key, value, cache.WithTrace(trace))
}
func (s *BaseStore) Get(key string, options ...cache.Option) (string, error) {
return s.cache.Get(key, options...)
}
func (s *BaseStore) GetT(key string, trace trace.T) (string, error) {
return s.Get(key, cache.WithTrace(trace))
}
func (s *BaseStore) GetModel(key string, value interface{}, options ...cache.Option) error {
if str, err := s.cache.Get(key, options...); err != nil {
return err
} else {
return json.Unmarshal([]byte(str), value)
}
}
func (s *BaseStore) GetModelT(key string, value interface{}, trace trace.T) error {
return s.GetModel(key, value, cache.WithTrace(trace))
}
func (s *BaseStore) Del(key string, options ...cache.Option) (int64, error) {
return s.cache.Del(key, options...)
}
func (s *BaseStore) DelT(key string, trace trace.T) (int64, error) {
return s.Del(key, cache.WithTrace(trace))
}
func (s *BaseStore) CheckGet(key string, options ...cache.Option) (string, error) {
return s.cache.CheckGet(key, options...)
}
func (s *BaseStore) CheckGetT(key string, trace trace.T) (string, error) {
return s.CheckGet(key, cache.WithTrace(trace))
}
func (s *BaseStore) CheckGetModel(key string, value interface{}, options ...cache.Option) error {
if str, err := s.cache.CheckGet(key, options...); err != nil {
return err
} else {
return json.Unmarshal([]byte(str), value)
}
}
func (s *BaseStore) CheckGetModelT(key string, value interface{}, trace trace.T) error {
return s.CheckGetModel(key, value, cache.WithTrace(trace))
}
func (s *BaseStore) Exists(key string) (bool, error) {
return s.cache.Exists(key)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。