Fast arbitrary data caching to tmp files in Go
go get -u github.com/miguelmota/go-filecache
https://godoc.org/github.com/miguelmota/go-filecache
package main
import (
"fmt"
"log"
"time"
"github.com/miguelmota/go-filecache"
)
func main() {
key := "foo"
data := []byte("bar") // can be of any type
expire := 1 * time.Hour
// caching data
err := filecache.Set(key, data, expire)
if err != nil {
log.Fatal(err)
}
// reading cached data
var dst []byte
found, err := filecache.Get(key, &dst)
if err != nil {
log.Fatal(err)
}
if found {
fmt.Println(string(dst)) // "bar"
}
}