This commit is contained in:
Lunny Xiao 2018-09-16 14:56:03 +08:00
parent fa23a9774a
commit 3542b3a933
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
3 changed files with 50 additions and 2 deletions

View File

@ -5,6 +5,7 @@
package xorm
import (
"context"
"database/sql"
"encoding/json"
"errors"
@ -52,6 +53,7 @@ type Session struct {
lastSQLArgs []interface{}
err error
context context.Context
}
// Clone copy all the session's content and return a new session

32
session_context.go Normal file
View File

@ -0,0 +1,32 @@
// Copyright 2018 The Xorm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package xorm
import (
"context"
)
type cacheContext struct {
context.Context
values map[string]interface{}
}
func (c *cacheContext) Done() <-chan struct{} {
for k := range c.values {
delete(c.values, k)
}
return nil
}
func (c *cacheContext) Value(key interface{}) interface{} {
return c.values[key.(string)]
}
func WithCacher(ctx context.Context) context.Context {
return &cacheContext{
Context: ctx,
values: make(map[string]interface{}),
}
}

View File

@ -66,7 +66,21 @@ func (session *Session) get(bean interface{}) (bool, error) {
}
}
return session.nocacheGet(beanValue.Elem().Kind(), table, bean, sqlStr, args...)
if session.context != nil {
//res := session.context.Value(fmt.Sprintf("%v-%v", sql, args))
//runtime.deepcopy()
//&res
}
has, err := session.nocacheGet(beanValue.Elem().Kind(), table, bean, sqlStr, args...)
if err != nil || !has {
return has, err
}
if session.context != nil {
//session.context.
}
return true, nil
}
func (session *Session) nocacheGet(beanKind reflect.Kind, table *core.Table, bean interface{}, sqlStr string, args ...interface{}) (bool, error) {