This repository contains example implementation of various cache replacement strategies. It accompanies this blog post Cache replacement strategies
Do not use these implementations for production workloads, they are not thread-safe and only support int
keys and values.
They are meant for educational and experimentation purposes.
However feel free to get inspiration from the source code when designing your own cache system for your use-case.
There are current six algorithms implemented in this repository as well as tests and benchmarks for them.
The interface of the package is intentionally left small to allow for more flexibility.
See godoc.
All algorithms implement the Cache
interface.
To keep it simple, the only supported type for keys and values is int
. This may be extended in the future.
To get an instance of a cache implementation, you need to use the Factory
function.
$ ./script/build
$ ./script/test
$ ./script/lint
$ ./script/benchmark
Calculate hit-rates with random input stream
$ go run ./cmd/hit-rate/main.go