cache
Thread-safe implementation of different cache algorithms in golang.
Blazing fast Get()
s, quite slow Set()
s.
issues | lists
go get git.sr.ht/~xn/cache/v2
// example: LRU
lru := cache.NewLRU[int](1000)
lru.Set("key", 10)
If you need only specific cache algorithm, you can import it without additional dependencies:
go get git.sr.ht/~xn/cache/v2/lfu
lfuCache := lfu.New[int](1000)
lfuCache.Set("key", 10)
status
implemented
tests
total: (statements) 100.0%
benchmarks
goos: linux
goarch: amd64
pkg: git.sr.ht/~xn/cache/v2/lfu
cpu: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
BenchmarkSet-8 6875901 205.2 ns/op 24 B/op 1 allocs/op
BenchmarkSetX2-8 38306 122613 ns/op 27 B/op 1 allocs/op
BenchmarkGet-8 8738271 171.2 ns/op 0 B/op 0 allocs/op
BenchmarkHas-8 14548699 122.9 ns/op 0 B/op 0 allocs/op
BenchmarkRemove-8 9629253 165.6 ns/op 0 B/op 0 allocs/op
BenchmarkPurge-8 10000 194397 ns/op 458826 B/op 3 allocs/op
goos: linux
goarch: amd64
pkg: git.sr.ht/~xn/cache/v2/lru
cpu: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
BenchmarkSet-8 5875112 210.3 ns/op 25 B/op 1 allocs/op
BenchmarkSetX2-8 39282 148461 ns/op 26 B/op 1 allocs/op
BenchmarkGet-8 5668399 229.2 ns/op 0 B/op 0 allocs/op
BenchmarkHas-8 14897650 95.25 ns/op 0 B/op 0 allocs/op
BenchmarkRemove-8 9606914 147.4 ns/op 0 B/op 0 allocs/op
BenchmarkPurge-8 10000 174681 ns/op 458827 B/op 3 allocs/op
goos: linux
goarch: amd64
pkg: git.sr.ht/~xn/cache/v2/tlru
cpu: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
BenchmarkSet-8 5374263 241.1 ns/op 32 B/op 1 allocs/op
BenchmarkSetX2-8 37250 143659 ns/op 34 B/op 1 allocs/op
BenchmarkGet-8 5046880 267.7 ns/op 0 B/op 0 allocs/op
BenchmarkHas-8 4878238 273.1 ns/op 0 B/op 0 allocs/op
BenchmarkRemove-8 9387120 145.5 ns/op 0 B/op 0 allocs/op
BenchmarkPurge-8 10000 184600 ns/op 458826 B/op 3 allocs/op
goos: linux
goarch: amd64
pkg: git.sr.ht/~xn/cache/v2/kv
cpu: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
BenchmarkSet-8 3892966 386.1 ns/op 167 B/op 0 allocs/op
BenchmarkGet-8 7877655 170.0 ns/op 0 B/op 0 allocs/op
BenchmarkHas-8 11948602 123.3 ns/op 0 B/op 0 allocs/op
BenchmarkRemove-8 8090110 165.6 ns/op 0 B/op 0 allocs/op
BenchmarkPurge-8 22674961 51.58 ns/op 48 B/op 1 allocs/op
PASS
ok git.sr.ht/~xn/cache/v2/kv 29.590s