Skip to content

pkg6/go-cache

Repository files navigation

GoCache

Go Report Card Go.Dev reference Sourcegraph Release

Installation

Make sure you have a working Go environment (Go 1.18 or higher is required). See the install instructions.

To install GoCache, simply run:

go get github.com/pkg6/go-cache

Example

package main

import (
	"github.com/pkg6/go-cache"
)

func main() {
	c := cache.New()
	c.Extend(cache.NewFileCache())
	c.Set("cache", "test", 0)
	c.Get("cache")
	c.GetMulti([]string{"cache"})
	c.Delete("cache")
	c.Has("cache")
	c.Increment("cache_inc", 1)
	c.Decrement("cache_dec", 1)
	c.Clear()
	c.Pull("cache")
	c.Remember("cache", func() any {
		return "test1"
	}, 0)
}