feat: add memory cache
This commit is contained in:
29
database/cache/new_test.go
vendored
29
database/cache/new_test.go
vendored
@ -1,6 +1,7 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@ -71,3 +72,31 @@ func TestNoAuth(t *testing.T) {
|
||||
// t.Fatal(err)
|
||||
//}
|
||||
}
|
||||
|
||||
func TestMemory(t *testing.T) {
|
||||
c, err := New(WithMemory())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
bs, err := c.Get(t.Context(), "haha")
|
||||
if err != nil {
|
||||
if !errors.Is(err, ErrorKeyNotFound) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
t.Logf("key not found")
|
||||
}
|
||||
|
||||
t.Logf("haha = %s", string(bs))
|
||||
|
||||
if err = c.Set(t.Context(), "haha", "haha"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if bs, err = c.Get(t.Context(), "haha"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
t.Logf("haha = %s", string(bs))
|
||||
}
|
||||
|
Reference in New Issue
Block a user