/cachier

Simple goCachier

Primary LanguageGo

Simple Cachier

Install

go get github.com/peric/cachier

Test

go test -v -race

Usage

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

Tips & Tricks

Source types

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.

Refreshing functionality

It's a bit primitive and it currently works just with seconds.

Keep in mind

This is my second GoLang app and I'm still reading my first book about it :)

GoLang book