Memory Caching in Golang. Preparing for Generics in go1.18.
It is the very simple memory cache with:
- Using built-in
map
of Golang which has been optimized. - Using
sync.Mutex
by shard for thread-safe and avoid cross-shards blocking. - Sharding keys with
xxh3
algorithm.
- Set
- SetUntil
- Get
- Take
- Delete
- GC
- Size
- Shard
- TTL
goos: darwin
goarch: amd64
pkg: github.com/lovung/memcache
cpu: Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
BenchmarkSet-8 7606341 132.5 ns/op 0 B/op 0 allocs/op
BenchmarkGet-8 11004312 114.6 ns/op 0 B/op 0 allocs/op
BenchmarkSetTake-8 4407631 267.9 ns/op 0 B/op 0 allocs/op
BenchmarkSetGetDel-8 4247701 276.4 ns/op 0 B/op 0 allocs/op