Least Recently Used cache implementation using Go. It's a proof of concept and shouldn't be used in production environments.
It exports one struct github.com/jonathanbeber/lru-cache/lru
.Cache
. Its constructor receives the maximum number of items to cache, a WrappableFunction
and a Logger
. Check the code documentation for more details (godoc
). After creating a lru.Cache
object, eg lruc
, invoke the wrapped function with lruc.Do(key)
.
For better understanding, read the example code in ./example
and run the factorial one with the command make factorial
.
This application is developed to go 1.14. Check the official docs for details on how to install it.
It uses golangci-lint and golint for code analyzes. It'll install them when running make lint
or make test
if the commands are not found.
The Makefile contains some commands for better productivity:
- To test the application use
make test
. It will run all the unit tests available. It will also run the following commands, available as separatedmake
commands:make fmt
: format all files usinggofmt
tool. It'll apply changes to the files. This project aggress on ceding control over minutiae of hand-formatting in favour of thegofmt
tool result;make vet
: examines Go source code and reports suspicious constructs;make lint
: runs the golangci-lint and the golint tool;
make factorial
run the code in./examples/factorial
.