-
Notifications
You must be signed in to change notification settings - Fork 0
/
callbacks.go
48 lines (40 loc) · 1007 Bytes
/
callbacks.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package hzgorm
import (
"errors"
"github.com/jinzhu/gorm"
)
func (hz *hzGorm) hazelcastBeforeCreateCallback(scope *gorm.Scope) {
if !hz.Options.CacheAfterPersist {
defer hz.removeQueryTtl()
hz.cachePut(scope)
}
}
func (hz *hzGorm) hazelcastAfterCreateCallback(scope *gorm.Scope) {
if hz.Options.CacheAfterPersist {
defer hz.removeQueryTtl()
hz.cachePut(scope)
}
}
func (hz *hzGorm) hazelcastBeforeUpdateCallback(scope *gorm.Scope) {
if !hz.Options.CacheAfterPersist {
defer hz.removeQueryTtl()
hz.cachePut(scope)
}
}
func (hz *hzGorm) hazelcastAfterUpdateCallback(scope *gorm.Scope) {
if hz.Options.CacheAfterPersist {
defer hz.removeQueryTtl()
hz.cachePut(scope)
}
}
func (hz *hzGorm) hazelcastBeforeQueryCallback(scope *gorm.Scope) {
scope.Err(errors.New("hazelcast cache"))
}
func (hz *hzGorm) hazelcastAfterQueryCallback(scope *gorm.Scope) {
hz.cacheHit(scope)
scope.Err(nil)
scope.DB().Error = nil
}
func (hz *hzGorm) removeQueryTtl() {
hz.Options.queryTtl = 0
}