summaryrefslogtreecommitdiffstats
path: root/vendor/xorm.io/xorm/caches
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/xorm.io/xorm/caches')
-rw-r--r--vendor/xorm.io/xorm/caches/encode.go9
-rw-r--r--vendor/xorm.io/xorm/caches/leveldb.go5
-rw-r--r--vendor/xorm.io/xorm/caches/manager.go4
3 files changed, 17 insertions, 1 deletions
diff --git a/vendor/xorm.io/xorm/caches/encode.go b/vendor/xorm.io/xorm/caches/encode.go
index 4ba39924a5..95536d7e54 100644
--- a/vendor/xorm.io/xorm/caches/encode.go
+++ b/vendor/xorm.io/xorm/caches/encode.go
@@ -13,22 +13,26 @@ import (
"io"
)
-// md5 hash string
+// Md5 return md5 hash string
func Md5(str string) string {
m := md5.New()
io.WriteString(m, str)
return fmt.Sprintf("%x", m.Sum(nil))
}
+
+// Encode Encode data
func Encode(data interface{}) ([]byte, error) {
//return JsonEncode(data)
return GobEncode(data)
}
+// Decode decode data
func Decode(data []byte, to interface{}) error {
//return JsonDecode(data, to)
return GobDecode(data, to)
}
+// GobEncode encode data with gob
func GobEncode(data interface{}) ([]byte, error) {
var buf bytes.Buffer
enc := gob.NewEncoder(&buf)
@@ -39,12 +43,14 @@ func GobEncode(data interface{}) ([]byte, error) {
return buf.Bytes(), nil
}
+// GobDecode decode data with gob
func GobDecode(data []byte, to interface{}) error {
buf := bytes.NewBuffer(data)
dec := gob.NewDecoder(buf)
return dec.Decode(to)
}
+// JsonEncode encode data with json
func JsonEncode(data interface{}) ([]byte, error) {
val, err := json.Marshal(data)
if err != nil {
@@ -53,6 +59,7 @@ func JsonEncode(data interface{}) ([]byte, error) {
return val, nil
}
+// JsonDecode decode data with json
func JsonDecode(data []byte, to interface{}) error {
return json.Unmarshal(data, to)
}
diff --git a/vendor/xorm.io/xorm/caches/leveldb.go b/vendor/xorm.io/xorm/caches/leveldb.go
index d1a177ad05..f2f71d8480 100644
--- a/vendor/xorm.io/xorm/caches/leveldb.go
+++ b/vendor/xorm.io/xorm/caches/leveldb.go
@@ -19,6 +19,7 @@ type LevelDBStore struct {
var _ CacheStore = &LevelDBStore{}
+// NewLevelDBStore creates a leveldb store
func NewLevelDBStore(dbfile string) (*LevelDBStore, error) {
db := &LevelDBStore{}
h, err := leveldb.OpenFile(dbfile, nil)
@@ -29,6 +30,7 @@ func NewLevelDBStore(dbfile string) (*LevelDBStore, error) {
return db, nil
}
+// Put implements CacheStore
func (s *LevelDBStore) Put(key string, value interface{}) error {
val, err := Encode(value)
if err != nil {
@@ -50,6 +52,7 @@ func (s *LevelDBStore) Put(key string, value interface{}) error {
return err
}
+// Get implements CacheStore
func (s *LevelDBStore) Get(key string) (interface{}, error) {
data, err := s.store.Get([]byte(key), nil)
if err != nil {
@@ -75,6 +78,7 @@ func (s *LevelDBStore) Get(key string) (interface{}, error) {
return s.v, err
}
+// Del implements CacheStore
func (s *LevelDBStore) Del(key string) error {
err := s.store.Delete([]byte(key), nil)
if err != nil {
@@ -89,6 +93,7 @@ func (s *LevelDBStore) Del(key string) error {
return err
}
+// Close implements CacheStore
func (s *LevelDBStore) Close() {
s.store.Close()
}
diff --git a/vendor/xorm.io/xorm/caches/manager.go b/vendor/xorm.io/xorm/caches/manager.go
index 05045210d2..89a141061a 100644
--- a/vendor/xorm.io/xorm/caches/manager.go
+++ b/vendor/xorm.io/xorm/caches/manager.go
@@ -6,6 +6,7 @@ package caches
import "sync"
+// Manager represents a cache manager
type Manager struct {
cacher Cacher
disableGlobalCache bool
@@ -14,6 +15,7 @@ type Manager struct {
cacherLock sync.RWMutex
}
+// NewManager creates a cache manager
func NewManager() *Manager {
return &Manager{
cachers: make(map[string]Cacher),
@@ -27,12 +29,14 @@ func (mgr *Manager) SetDisableGlobalCache(disable bool) {
}
}
+// SetCacher set cacher of table
func (mgr *Manager) SetCacher(tableName string, cacher Cacher) {
mgr.cacherLock.Lock()
mgr.cachers[tableName] = cacher
mgr.cacherLock.Unlock()
}
+// GetCacher returns a cache of a table
func (mgr *Manager) GetCacher(tableName string) Cacher {
var cacher Cacher
var ok bool