Skip to content

jairoblatt/BeerCache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BeerCache 🍺

BeerCache - Fast & Cold

Fast and Cold - A minimalist in-memory database via Unix sockets

What is it?

BeerCache is a simple and fast key-value database that runs in memory and communicates via Unix sockets. Perfect for local caching, sessions, or anything that needs to be as fast.

Features

  • In-memory: Everything stays in RAM, zero disk latency
  • Unix Sockets: Ultra-fast local communication
  • Thread-safe: Uses DashMap for concurrent access
  • Binary protocol: Efficient and compact
  • CRUD operations: Complete Create, Read, Update, Delete

Usage

Start the server

# Default socket: /tmp/beer_cache.sock
cargo run

# Custom socket
SOCKET_NAME=my_cache cargo run

Available operations

Operation Code Description
GET 1 Fetch a resource
GET_ALL 2 List all resources
SET 3 Create/update a resource
UPDATE 4 Update existing resource
DELETE 5 Remove a resource
DELETE_ALL 6 Clear everything

Status codes

Code Status Description
1 OK Success
2 CREATED Resource created
3 NOT_FOUND Resource not found
4 BAD_REQUEST Invalid request

Protocol

BeerCache uses a simple binary protocol over Unix sockets.

Message format

[4 bytes: content_length][content]

Request format

[1 byte: operation][16 bytes: resource_id (optional)][body (optional)]

Response format

[4 bytes: content_length][1 byte: status_code][payload (optional)]

Examples

GET operation

Request:  [length][1][resource_id]
Response: [length][1][resource_body]

SET operation

Request:  [length][3][resource_id][resource_body]
Response: [length][2] (if created) or [length][1] (if updated)

GET_ALL operation

Request:  [length][2]
Response: [length][1][id1][body1_length][body1][id2][body2_length][body2]...

Resource ID

  • Fixed 16-byte array
  • Can be any binary data (UUIDs work great)

Building

cargo build --release

Dependencies

  • tokio: Async runtime
  • dashmap: Concurrent HashMap

License

Do whatever you want with it. It's just a cache.

About

🍺 A minimalist in-memory database via Unix sockets

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors