package main
import (
"fmt"
"github.com/gogf/gf/v2/os/gcache"
"github.com/gogf/gf/v2/os/gctx"
)
func main() {
type User struct {
Id int
Name string
Site string
}
var (
ctx = gctx.New()
user *User
key = `UserKey`
value = &User{
Id: 1,
Name: "GoFrame",
Site: "https://goframe.org",
}
)
err := gcache.Set(ctx, key, value, 0)
if err != nil {
panic(err)
}
v, err := gcache.Get(ctx, key)
if err != nil {
panic(err)
}
if err = v.Scan(&user); err != nil {
panic(err)
}
fmt.Printf(`%#v`, user)
}