micache

package module
v0.0.0-...-a0e1f0d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2019 License: MIT Imports: 7 Imported by: 0

README

micache

go mini file cache

get micahce

$ go get gitee.com/migopher/micache
Set Cache File Path
package main

import "gitee.com/migopher/micache"

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

Set Cache

set cache and time

package main

import "gitee.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"
	"gitee.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"
	"gitee.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"
	"gitee.com/migopher/micache"
)

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

Delete Key

delete cache key

package main

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Dir string = "runtime/cache/"
View Source
var Error string

Functions

func Delete

func Delete(key string) bool

* delete cache file

func Get

func Get(key string) interface{}

* key get cache

func GetDecoding

func GetDecoding(key string, value interface{}) bool

* get struct decoding

func IsExist

func IsExist(key string) bool

* key is exists

func Set

func Set(key string, value interface{}, timeNum int64) bool

* set cache

Types

type Cache

type Cache struct {
	Time     int64
	Value    interface{}
	Expires  int64
	FilePath string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL