Cache some things and stuff.
Install:
go get -u github.com/ngerakines/yacache
Import:
import "github.com/ngerakines/yacache"
func ExampleNewCache_Get() {
ctx := context.Background()
c := NewCache()
key := Key("foo")
fetcher := func(ctx context.Context, fkey yacache.Key) (yacache.Cacheable, error) {
return NewCacheableValue("bar", 1*time.Hour), nil
}
if item, err := c.Get(ctx, key, fetcher); err == nil {
fmt.Println(item.Value())
}
if item, err := c.Get(ctx, key, fetcher); err == nil {
fmt.Println(item.Value())
}
// Output: bar
// bar
}