添加缓存失效设置
This commit is contained in:
parent
7de30d1a69
commit
028727449b
@ -11,6 +11,7 @@ import (
|
||||
"go_dreamfactory/sys/cache"
|
||||
"go_dreamfactory/sys/db"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
@ -108,7 +109,8 @@ func (this *Model_Comp) UpdateModelLogs(table string, uID string, where bson.M,
|
||||
//data 值允许protobuf格式的对象
|
||||
// attrs 操作可选项目 eg.传入WithDisabledMgoLog() 表示关闭日志,否则开启;WithND() 传入表示插入操作,不传表示更新,前提不能传入传入WithDisabledMgoLog()
|
||||
func (this *Model_Comp) SetObj(uid string, data proto.Message, attrs ...*cache.OperationAttr) error {
|
||||
err := this.Redis.Set(this.ukey(uid), data, 0)
|
||||
expr := cache.OperationAttrs(attrs).Find(cache.ATTR_EXPIRE).Unwrap_Or(time.Second * 0).(time.Duration)
|
||||
err := this.Redis.Set(this.ukey(uid), data, expr)
|
||||
if err != nil {
|
||||
log.Errorf("set err:%v", err)
|
||||
return err
|
||||
|
@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"go_dreamfactory/modules/dbservice"
|
||||
"go_dreamfactory/modules/friend"
|
||||
"go_dreamfactory/modules/mail"
|
||||
"go_dreamfactory/modules/pack"
|
||||
@ -41,7 +40,7 @@ func main() {
|
||||
pack.NewModule(),
|
||||
mail.NewModule(),
|
||||
friend.NewModule(),
|
||||
dbservice.NewModule(),
|
||||
// dbservice.NewModule(),
|
||||
)
|
||||
|
||||
}
|
||||
|
16
sys/cache/optionAttr.go
vendored
16
sys/cache/optionAttr.go
vendored
@ -1,8 +1,12 @@
|
||||
package cache
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
ATTR_EXPIRE = "expire"
|
||||
ATTR_MGOLOG = "mgolog"
|
||||
ATTR_INSERT = "insert"
|
||||
|
||||
@ -32,6 +36,15 @@ func (this OperationAttrs) Find(name string) *InterfaceResult {
|
||||
return NewInterfaceResult(nil, fmt.Errorf("Operationattrs not found err: %v", name))
|
||||
}
|
||||
|
||||
//缓存过期时间设置
|
||||
func WithExpire(t time.Duration) *OperationAttr {
|
||||
return &OperationAttr{
|
||||
Name: ATTR_EXPIRE,
|
||||
Value: t,
|
||||
}
|
||||
}
|
||||
|
||||
//禁用Mgolog操作
|
||||
func WithDisabledMgoLog() *OperationAttr {
|
||||
return &OperationAttr{
|
||||
Name: ATTR_MGOLOG,
|
||||
@ -39,6 +52,7 @@ func WithDisabledMgoLog() *OperationAttr {
|
||||
}
|
||||
}
|
||||
|
||||
//新记录插入操作
|
||||
func WithND() *OperationAttr {
|
||||
return &OperationAttr{
|
||||
Name: ATTR_INSERT,
|
||||
|
Loading…
Reference in New Issue
Block a user