feat: add memory cache

This commit is contained in:
zhaoyupeng
2025-07-15 18:40:13 +08:00
parent 127c57dc3a
commit 868b959c6f
7 changed files with 239 additions and 29 deletions

View File

@ -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))
}