golib/gcache/memory_test.go

32 lines
528 B
Go
Raw Normal View History

2023-10-11 07:36:56 +08:00
//
// memory_test.go
// Copyright (C) 2023 tiglog <me@tiglog.com>
//
// Distributed under terms of the MIT license.
//
package gcache_test
import (
"testing"
"time"
"git.hexq.cn/tiglog/golib/gcache"
"git.hexq.cn/tiglog/golib/gtest"
)
func TestUsage(t *testing.T) {
c := gcache.NewMemCache()
c.Set("a", 1)
c.Set("b", 1, gcache.WithEx(1*time.Second))
time.Sleep(1 * time.Second)
r1, ok := c.Get("a") // 1, true
gtest.True(t, ok)
gtest.Equal(t, 1, r1)
r2, ok := c.Get("b")
gtest.False(t, ok)
gtest.Nil(t, r2)
}