Skip to content
/ cache Public
forked from goburrow/cache

Mango Cache - Partial implementations of Guava Cache in Go.

License

Notifications You must be signed in to change notification settings

d0ngw/cache

 
 

Repository files navigation

Mango Cache

GoDoc Build Status

Partial implementations of Guava Cache in Go.

Supported cache replacement policies:

  • LRU
  • Segmented LRU (default)
  • TinyLFU (experimental)

The TinyLFU implementation is inspired by Caffeine by Ben Manes and go-tinylfu by Damian Gryski.

Download

go get -u github.com/goburrow/cache

Example

package main

import (
	"fmt"
	"math/rand"
	"time"

	"github.com/goburrow/cache"
)

func main() {
	load := func(k cache.Key) (cache.Value, error) {
		return fmt.Sprintf("%d", k), nil
	}
	// Create a new cache
	c := cache.NewLoadingCache(load,
		cache.WithMaximumSize(1000),
		cache.WithExpireAfterAccess(10*time.Second),
		cache.WithRefreshAfterWrite(60*time.Second),
	)

	getTicker := time.Tick(10 * time.Millisecond)
	reportTicker := time.Tick(1 * time.Second)
	for {
		select {
		case <-getTicker:
			_, _ = c.Get(rand.Intn(2000))
		case <-reportTicker:
			st := cache.Stats{}
			c.Stats(&st)
			fmt.Printf("%+v\n", st)
		}
	}
}

Performance

See traces

report

About

Mango Cache - Partial implementations of Guava Cache in Go.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%