go get github.com/peric/cachier
go test -v -race
import (
"github.com/peric/cachier"
"fmt"
)
func main() {
// define sources
cachier.AddSource(&Source{Key: "kiwi", RefreshEverySeconds: 60, Type: cachier.TypeJson})
cachier.AddSource(&Source{Key: "goavio", RefreshEverySeconds: 600, Type: cachier.TypeJson})
// init cache and method that will refresh sources
cachier.Init()
// get already initialized data
value0 := cachier.Get("kiwi", "awesomekey")
fmt.Println(value0)
// set additional data if needed
cachier.Set("kiwi", "awesomekey3", "Best value")
// get data
value1 := cachier.Get("kiwi", "awesomekey3")
fmt.Println(value1)
}
Application is now fetching only from local JSON files. So if we would like to fetch the data from db or API, we would need additional implementations. But in any case, received data would be structured the same as it is now.
It's a bit primitive and it currently works just with seconds.
This is my second GoLang app and I'm still reading my first book about it :)