- listens on a Unix domain socket and accepts simple PUT, GET, DEL, INFO text+binary commands,
- persists metadata in BadgerDB (URL → JSON metadata: path, expiry, size, lastAccess),
- keeps an in-memory LRU (doubly-linked list) backed by Badger (lastAccess persisted on each access) so the LRU survives restarts,
- enforces a total-size eviction policy (LRU eviction) with a configurable size limit,
- writes files atomically (write temp file then rename),
- uses per-key locks + global LRU lock to avoid races,
- recalculates total size & rebuilds LRU on startup from Badger entries,
- handles concurrent clients safely.
go run ./cmd/server ./cache ./cache.sock ./badger 100000000
# send a small test payload
printf "PUT https://example.com/a 3600 11\nhello world" | socat - UNIX-CONNECT:./cache.sock
printf "GET https://example.com/a\n" | socat - UNIX-CONNECT:./cache.sock | { read -r header; echo "HEADER: $header"; dd bs=1 count=$(echo $header | awk '{print $2}'); }
go run ./cmd/cli ./cache.sock put https://example.com/img logo.png 3600
go run ./cmd/cli ./cache.sock get https://example.com/img out.png
go run ./cmd/cli ./cache.sock info
go run ./cmd/cli ./cache.sock del https://example.com/img