forked from go-xorm/xorm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache_lru_test.go
52 lines (40 loc) · 1.11 KB
/
cache_lru_test.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
49
50
51
52
// Copyright 2015 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 (
"testing"
"xorm.io/core"
"github.com/stretchr/testify/assert"
)
func TestLRUCache(t *testing.T) {
type CacheObject1 struct {
Id int64
}
store := NewMemoryStore()
cacher := NewLRUCacher(store, 10000)
tableName := "cache_object1"
pks := []core.PK{
{1},
{2},
}
for _, pk := range pks {
sid, err := pk.ToString()
assert.NoError(t, err)
cacher.PutIds(tableName, "select * from cache_object1", sid)
ids := cacher.GetIds(tableName, "select * from cache_object1")
assert.EqualValues(t, sid, ids)
cacher.ClearIds(tableName)
ids2 := cacher.GetIds(tableName, "select * from cache_object1")
assert.Nil(t, ids2)
obj2 := cacher.GetBean(tableName, sid)
assert.Nil(t, obj2)
var obj = new(CacheObject1)
cacher.PutBean(tableName, sid, obj)
obj3 := cacher.GetBean(tableName, sid)
assert.EqualValues(t, obj, obj3)
cacher.DelBean(tableName, sid)
obj4 := cacher.GetBean(tableName, sid)
assert.Nil(t, obj4)
}
}