Skip to content

UltraSive/web-asset-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

web-asset-cache

  • 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.

Start with 100MB LRU

go run ./cmd/server ./cache ./cache.sock ./badger 100000000

Testing

# 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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published