Skip to content

simple go library to manage number of data in cache

Notifications You must be signed in to change notification settings

michaelwp/go-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-cache

simple go library to manage number of data in cache

installation:

go get -d github.com/michaelwp/go-cache

example on how to use it:

package main

import (
	"fmt"
	gocache "github.com/michaelwp/go-cache"
)

func main() {
	capacity := int32(3)
	cache := gocache.NewCache(capacity)

	// add new data to cache
	cache.Add("A", "testA")
	cache.Add("B", "testB")
	cache.Add("C", "testC")
	cache.Add("D", "testD")
	cache.Add("E", "testE")

	// get data from cache
	valA, isAExist := cache.Get("A")
	if !isAExist {
		fmt.Println("A key doesn't exist")
	} else {
		fmt.Println("A:", valA)
	}

	valD, isDExist := cache.Get("D")
	if !isDExist {
		fmt.Println("D key doesn't exist")
	} else {
		fmt.Println("D:", valD)
	}

	cache.Add("F", "testF")
	cache.Add("G", "testG")

	fmt.Println("cache:", cache.View())
}

About

simple go library to manage number of data in cache

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages