-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbigcache_test.go
More file actions
42 lines (34 loc) · 943 Bytes
/
bigcache_test.go
File metadata and controls
42 lines (34 loc) · 943 Bytes
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
package cachex
import (
"context"
"testing"
"time"
"github.com/allegro/bigcache/v3"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func newBigCache(tb testing.TB) *BigCache {
cache, err := NewBigCache(context.Background(), BigCacheConfig{
Config: bigcache.Config{
Shards: 16,
LifeWindow: 1 * time.Minute,
CleanWindow: 1 * time.Second,
MaxEntriesInWindow: 1000,
MaxEntrySize: 100,
},
})
require.NoError(tb, err)
tb.Cleanup(func() { cache.Close() })
return cache
}
func TestBigCacheBasics(t *testing.T) {
ctx := context.Background()
cache := newBigCache(t)
require.NoError(t, cache.Set(ctx, "key1", []byte("value1")))
value, err := cache.Get(ctx, "key1")
require.NoError(t, err)
assert.Equal(t, []byte("value1"), value)
require.NoError(t, cache.Del(ctx, "key1"))
_, err = cache.Get(ctx, "key1")
assert.True(t, IsErrKeyNotFound(err))
}