gache is thinnest cache library for go application
Go 1.11
go get github.com/kpango/gache
// data sets
var (
key1 = "key"
key2 = 5050
key3 = struct{}{}
value1 = "value"
value2 = 88888
value3 = struct{}{}
)
// store cache default expire is 30 Seconds
gache.Set(key1, value3)
gache.Set(key2, value2)
gache.Set(key3, value1)
// load cache data
v1, ok := gache.Get(key1)
v2, ok := gache.Get(key2)
v3, ok := gache.Get(key3)
gache.Write(context.Background(), glg.FileWriter("./gache-sample.gdb", 0755))
gache.New().SetDefaultExpire(time.Minute).Read(glg.FileWriter("./gache-sample.gdb", 0755))
gache vs gocache vs normal map with lock vs go-cache vs gcache vs freecache vs bigcache vs go-mcache
go test -count=1 -run=NONE -bench . -benchmem
goos: darwin
goarch: amd64
pkg: github.com/kpango/gache
BenchmarkGacheWithSmallDataset-8 10000000 217 ns/op 192 B/op 8 allocs/op
BenchmarkGacheWithBigDataset-8 500 3367835 ns/op 480004 B/op 20000 allocs/op
BenchmarkGocacheWithSmallDataset-8 5000000 371 ns/op 320 B/op 16 allocs/op
BenchmarkGocacheWithBigDataset-8 300 3913257 ns/op 809037 B/op 40092 allocs/op
BenchmarkFastCacheWithSmallDataset-8 1000000 1061 ns/op 40 B/op 4 allocs/op
BenchmarkFastCacheWithBigDataset-8 50 24633452 ns/op 126797919 B/op 39986 allocs/op
BenchmarkMapWithSmallDataset-8 1000000 1381 ns/op 128 B/op 8 allocs/op
BenchmarkMapWithBigDataset-8 100 10477737 ns/op 332664 B/op 20001 allocs/op
BenchmarkFreeCacheWithSmallDataset-8 1000000 1226 ns/op 26 B/op 4 allocs/op
BenchmarkFreeCacheWithBigDataset-8 100 20914503 ns/op 126812350 B/op 39938 allocs/op
BenchmarkBigCacheWithSmallDataset-8 1000000 1416 ns/op 418 B/op 8 allocs/op
BenchmarkBigCacheWithBigDataset-8 20 54483710 ns/op 219245782 B/op 30273 allocs/op
BenchmarkGoCacheWithSmallDataset-8 1000000 1506 ns/op 64 B/op 4 allocs/op
BenchmarkGoCacheWithBigDataset-8 100 10465906 ns/op 175742 B/op 10002 allocs/op
BenchmarkGCacheLRUWithSmallDataset-8 500000 2450 ns/op 320 B/op 16 allocs/op
BenchmarkGCacheLRUWithBigDataset-8 100 21327392 ns/op 1976773 B/op 60154 allocs/op
BenchmarkGCacheLFUWithSmallDataset-8 500000 2953 ns/op 512 B/op 20 allocs/op
BenchmarkGCacheLFUWithBigDataset-8 100 22398865 ns/op 1440065 B/op 49989 allocs/op
BenchmarkGCacheARCWithSmallDataset-8 500000 3121 ns/op 320 B/op 16 allocs/op
BenchmarkGCacheARCWithBigDataset-8 20 66966396 ns/op 3010356 B/op 80309 allocs/op
BenchmarkMCacheWithSmallDataset-8 100000 14009 ns/op 4358 B/op 40 allocs/op
BenchmarkMCacheWithBigDataset-8 30 37309669 ns/op 11098881 B/op 100002 allocs/op
PASS
ok github.com/kpango/gache 37.067s
- Fork it ( https://github.com/kpango/gache/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create new Pull Request
gache released under MIT license, refer LICENSE file.