/micache

go mini file cache

Primary LanguageGoMIT LicenseMIT

micache

go mini file cache

get micahce

$ go get github.com/migopher/micache

Set Cache File Path

package main

import "github.com/migopher/micache"

func main() {
	// set cache file path cache/
	micache.Dir="cache/"
}

Set Cache

set cache and time

package main

import "github.com/migopher/micache"

func main() {
	// set key expiration time 3600s or 0 is permanent save
	micache.Set("go", "golang", 3600)
}

Get Cache

get key cache value

package main

import (
	"fmt"
	"github.com/migopher/micache"
)

func main() {
	// get key cache value
	v := micache.Get("go")
	fmt.Println(v)
}

Get Struct

get key cache struct value

package main

import (
	"fmt"
	"github.com/migopher/micache"
)

type User struct {
	Uid      int
	UserName string
}

func main() {
	getUser:=User{}
	micache.GetDecoding("go", &getUser)
	fmt.Println(getUser)
}

Key Is Exist

package main

import (
	"fmt"
	"github.com/migopher/micache"
)

func main() {
	b:=micache.IsExist("go")
	fmt.Println(b)
}

Delete Key

delete cache key

package main

import (
	"fmt"
	"github.com/migopher/micache"
)

func main() {
	b:=micache.Delete("go")
	fmt.Println(b)
}