Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

miguelmota/go-filecache

Repository files navigation


logo


go-filecache

Fast arbitrary data caching to tmp files in Go

License Build Status Go Report Card GoDoc

Install

go get -u github.com/miguelmota/go-filecache

Documentation

https://godoc.org/github.com/miguelmota/go-filecache

Getting started

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"
	}
}

License

MIT