Skip to content

wang1309/gcache

Repository files navigation

image

What is gcache?

gcache is a high-performance Go language implementation of a cache library. It is easy to use and understand

Design principle?

  • LRU elimination algorithm
  • Use singleflight to avoid cache pinging
  • Support custom load method
  • Support cache change listener
TODO

Map shard

How to install ?

go get -u github.com/wang1309/gcache

use case

init cache object

import (
	"sync"
	"time"
	"golang.org/x/sync/singleflight"
	"github.com/wang1309/gcache"
)

const maxItems = 100

func main() {
	// create cache object
	c := cache.NewCache(loader, maxItems)
}

func loader(key string) interface{} {
	// get data by key
	return "value"
}

Get

value := c.Get("key")

Put

c.Put("key", "value")

Benchmark

ENV

goos: darwin goarch: arm64

BenchmarkCache_GetParallel/Get-8                 3000000               314.4 ns/op
BenchmarkCache_Put-8     3000000               190.4 ns/op

About

go cache manage lib

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages