gf/os/gfile/gfile_z_example_cache_test.go
2021-11-11 13:01:32 +08:00

36 lines
703 B
Go

package gfile_test
import (
"fmt"
"time"
"github.com/gogf/gf/v2/os/gfile"
)
func ExampleGetContentsWithCache() {
// init
var (
fileName = "gflie_example.txt"
tempDir = gfile.TempDir("gfile_example_cache")
tempFile = gfile.Join(tempDir, fileName)
)
// write contents
gfile.PutContents(tempFile, "goframe example content")
// read contents
fmt.Println(gfile.GetContentsWithCache(tempFile, time.Minute))
// write new contents will clear its cache
gfile.PutContents(tempFile, "new goframe example content")
time.Sleep(time.Second * 1)
// read contents
fmt.Println(gfile.GetContentsWithCache(tempFile))
// Output:
// goframe example content
// new goframe example content
}