Skip to content

Latest commit

 

History

History
66 lines (48 loc) · 1.32 KB

README.md

File metadata and controls

66 lines (48 loc) · 1.32 KB

microcache

In memory cache library for golang

GoDoc Go Report Card GoCover

How to use

Simple usage:

import (
	"fmt"

	"github.com/lpicanco/microcache"
	"github.com/lpicanco/microcache/configuration"
)

func main() {
	cache := microcache.New(configuration.DefaultConfiguration(100))
	cache.Put(42, "answer")

	value, found := cache.Get(42)
	if found {
		fmt.Printf("Value: %v\n", value)
	}

	fmt.Printf("Cache len: %v\n", cache.Len())

	cache.Invalidate(42)
}

Custom options:

import (
	"fmt"
	"time"

	"github.com/lpicanco/microcache"
	"github.com/lpicanco/microcache/configuration"
)

func main() {
	cache := microcache.New(configuration.Configuration{
		MaxSize:           10000,
		ExpireAfterWrite:  1 * time.Hour,
		ExpireAfterAccess: 10 * time.Minute,
		CleanupCount:      5,
	})
	cache.Put(42, "answer")

	value, found := cache.Get(42)
	if found {
		fmt.Printf("Value: %v\n", value)
	}

	fmt.Printf("Cache len: %v\n", cache.Len())

	cache.Invalidate(42)
}