-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcache_test.go
52 lines (45 loc) · 1.3 KB
/
cache_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
package fcache
import (
"testing"
"time"
)
func TestMemoryCache(t *testing.T) {
cache := newMemCache(10, false, 0)
cache.Set("key1", []byte("123456789"))
cache.Set("key2", []byte("0"))
t.Log(cache.Get("key1"))
t.Log(cache.Get("key2"))
}
func TestDiskCache(t *testing.T) {
cache := newDiskCache(10, false, "./cache", 0)
cache.Set("key1", []byte("123456789"))
cache.Set("key2", []byte("0"))
t.Log(cache.Get("key1"))
t.Log(cache.Get("key2"))
}
func TestClear(t *testing.T) {
memCache := newMemCache(10, false, 0)
memCache.Set("key1", []byte("123456789"))
t.Log(memCache.Get("key1"))
t.Log(memCache.Clear("key1"))
t.Log(memCache.Get("key1"))
diskCache := newDiskCache(10, false, "./cache", 0)
diskCache.Set("key1", []byte("123456789"))
t.Log(diskCache.Get("key1"))
time.Sleep(time.Second)
t.Log(diskCache.Clear("key1"))
t.Log(diskCache.Get("key1"))
}
func TestClearAll(t *testing.T) {
memCache := newMemCache(100, false, 0)
memCache.Set("key1", []byte("123456789"))
memCache.Set("key2", []byte("123456789"))
t.Log(memCache.ClearAll())
t.Log(memCache.Get("key1"))
diskCache := newDiskCache(100, false, "./cache", 0)
t.Log(diskCache.Set("key1", []byte("123456789")))
t.Log(diskCache.Set("key2", []byte("123456789")))
time.Sleep(time.Second)
t.Log(diskCache.ClearAll())
t.Log(diskCache.Get("key1"))
}