A lightweight HTTP-based distributed cache service written in Go with:
- LRU eviction
- Optional TTL per key
- Save/load persistence to disk
- Basic replica forwarding support
- Consistent hash client library (
client/)
- Go 1.26+
go run main.go -port 8000 -capacity 100# set key
curl "http://localhost:8000/set?key=user&value=john"
# get key
curl "http://localhost:8000/get?key=user"
# set with ttl (seconds)
curl "http://localhost:8000/set?key=temp&value=123&ttl=60"
# save cache to disk
curl "http://localhost:8000/save?file=cache.json"
# load cache from disk
curl "http://localhost:8000/load?file=cache.json"docker build -t distributed-cache:latest .docker run --rm -p 8000:8000 distributed-cache:latestServer will be available at:
http://localhost:8000/- Container runs as non-root user and includes a healthcheck on
/.
docker compose up --buildThis starts one service:
distributed-cacheon port8000- with
restart: unless-stoppedand a built-in healthcheck.
.
|-- main.go
|-- Dockerfile
|-- docker-compose.yml
|-- cache/
| |-- cache.go
| |-- lru.go
| `-- persistence.go
|-- server/
| `-- server.go
|-- hash/
| `-- consistent_hash.go
`-- client/
`-- client.go
- Keys set without
ttldo not expire. GET /getreturns404when key is not found or expired.- Persistence files are created inside the running container/app working directory.