wp-go/cache/vars_test.go

36 lines
618 B
Go
Raw Permalink Normal View History

2023-01-20 10:43:11 +00:00
package cache
import (
"context"
"fmt"
"testing"
"time"
)
2023-11-02 14:40:13 +00:00
var cc = *NewVarCache[int](NewVarMemoryCache[int](func() time.Duration {
return time.Minute
}), func(ctx context.Context, a ...any) (int, error) {
2023-01-20 10:43:11 +00:00
return 1, nil
2023-11-02 14:40:13 +00:00
})
2023-01-20 10:43:11 +00:00
func TestVarCache_Flush(t *testing.T) {
type testCase[T any] struct {
name string
c VarCache[T]
}
tests := []testCase[int]{
{
name: "1",
c: cc,
},
}
c := context.Background()
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
fmt.Println(tt.c.GetCache(c, time.Second))
2023-11-02 14:40:13 +00:00
tt.c.Flush(ctx)
2023-01-20 10:43:11 +00:00
fmt.Println(tt.c.GetCache(c, time.Second))
})
}
}