BoltCache π
Note: This project was coded by vibe.
High-performance, Redis-compatible in-memory cache with RESTful API
BoltCache is a modern, fast, and scalable in-memory cache system built in Go. It provides Redis-like functionality with better performance, RESTful API support, and enterprise-grade features.
Keywords:
redis,cache,in-memory,golang,rest-api,pub-sub,high-performance,microservices,docker,kubernetes
β¨ Features
- β‘ High Performance: Optimized for write-heavy workloads (up to 2x faster SET operations than Redis)
- π RESTful API: Modern HTTP/JSON interface alongside TCP protocol
- π Pub/Sub Messaging: Real-time messaging with WebSocket support
- β° TTL Support: Automatic key expiration and cleanup
- π Thread-Safe: Concurrent operations with lock-free data structures
- πΎ Persistence: JSON-based disk storage with backup support
- π Clustering: Master-slave replication and high availability
- π Complex Data Types: String, List, Set, Hash support
- π§ Lua Scripting: Execute custom scripts for complex operations
- π‘οΈ Security: Token-based authentication and rate limiting
- π Monitoring: Built-in metrics, health checks, and profiling
- βοΈ Configuration: YAML-based configuration management
π Quick Start
Prerequisites
- Go 1.21 or higher
- Git
Installation
# Clone the repository git clone https://github.com/wutlu/boltcache.git cd boltcache # Install dependencies go mod download # Generate default configuration make generate-config # Start the server make run-dev
The server will start on:
- REST API: http://localhost:8090
- TCP Server: localhost:6380
- GNet Server: localhost:6381 (High Performance)
Quick Test
# Health check curl http://localhost:8090/ping # Set a value curl -X PUT http://localhost:8090/cache/hello \ -H "Content-Type: application/json" \ -d '{"value": "world"}' # Get the value curl http://localhost:8090/cache/hello # Test TCP protocol telnet localhost 6380 SET mykey myvalue GET mykey PING
π Usage
REST API
BoltCache provides a comprehensive RESTful API:
String Operations
# Set value PUT /cache/{key} {"value": "data", "ttl": "5m"} # Get value GET /cache/{key} # Delete key DELETE /cache/{key}
List Operations
# Push to list POST /list/{key} ["item1", "item2"] # Pop from list DELETE /list/{key}
Set Operations
# Add to set POST /set/{key} ["member1", "member2"] # Get set members GET /set/{key}
Hash Operations
# Set hash field PUT /hash/{key}/{field} {"value": "data"} # Get hash field GET /hash/{key}/{field}
Pub/Sub Operations
# Publish message POST /publish/{channel} {"message": "Hello World"} # Subscribe (WebSocket) GET /subscribe/{channel}
Lua Scripting
# Execute script POST /eval { "script": "redis.call('SET', KEYS[1], ARGV[1])", "keys": ["mykey"], "args": ["myvalue"] }
Configuration
BoltCache uses YAML configuration files:
# config.yaml server: mode: "rest" # tcp, rest, both rest: port: 8090 cors_enabled: true tcp: port: 6380 cache: max_memory: "1GB" cleanup_interval: "1m" eviction_policy: "lru" persistence: enabled: true file: "./data/cache.json" interval: "30s" security: auth: enabled: true tokens: ["your-secret-token"]
Environment-Specific Configs
# Development make run-dev # Production make run-prod # Custom config go run . server --config custom.yaml
π§ Development
Available Commands
# Server operations make run # Run with default config make run-dev # Run development mode make run-prod # Run production mode make build # Build binary # Configuration make generate-config # Generate default config make validate-config # Validate configuration make show-config # Show current config # Testing make test-rest # Test REST API make test-auth # Test authentication make test-pubsub # Test Pub/Sub messaging # Web client: http://localhost:8090/rest-client.html # Clustering make cluster-master # Start cluster master make cluster-slave # Start cluster slave
Testing Tools
-
Web Client: Interactive browser-based client
# Start server make run-dev # Open web client open http://localhost:8090/rest-client.html
-
Postman Collection: Import
BoltCache.postman_collection.json -
cURL Scripts:
./examples/rest-examples.sh ./examples/auth-examples.sh ./examples/test-pubsub.sh
-
Interactive Client:
go run . client interactive --addr :6380
π‘οΈ Security
Authentication
BoltCache supports token-based authentication:
# Using Authorization header curl -H "Authorization: Bearer your-token" \ http://localhost:8090/cache/key # Using X-API-Token header curl -H "X-API-Token: your-token" \ http://localhost:8090/cache/key # Using query parameter curl "http://localhost:8090/cache/key?token=your-token"
Configuration
security: auth: enabled: true method: "token" tokens: - "production-token-1" - "production-token-2" rate_limit: enabled: true requests_per_second: 1000 burst: 100
π Performance
Benchmarks
BoltCache outperforms Redis significantly in write-heavy operations, especially when using pipelining.
Test Environment: MacBook Pro M1/M2/M3 (Localhost loopback) Concurrency: 100 clients, 100,000 operations Pipelining: Batch size 100
| Operation | BoltCache Ultra | Redis | Improvement |
|---|---|---|---|
| SET (Standard) | ~75,955 ops/s | 58,613 ops/s | 1.3x FASTER π |
| SET (Pipelined) | ~698,542 ops/s | 361,009 ops/s | 1.9x FASTER π |
| GET (Standard) | ~77,301 ops/s | 81,667 ops/s | 0.95x |
| GET (Pipelined) | ~820,683 ops/s | 1,199,741 ops/s | 0.68x |
Benchmark Scripts: You can verify these results yourself using the provided benchmark tools:
Performance Tuning
performance: max_goroutines: 10000 gc_percent: 100 connection_pool: max_idle: 100 max_active: 1000
ποΈ Architecture
Core Components
- Storage Engine: Lock-free
sync.Mapfor concurrent access - Network Layer: HTTP/REST and TCP protocol support
- Pub/Sub System: Channel-based non-blocking messaging
- Persistence Layer: JSON-based storage with compression
- Authentication: Token-based security middleware
- Configuration: YAML-based configuration management
Data Flow
Client Request β Auth Middleware β Router β Cache Engine β Storage
β
Pub/Sub System β Background Tasks β Persistence Layer
π³ Docker Deployment
Single Node
# Build image docker build -t boltcache . # Run container docker run -p 8090:8090 -v ./data:/app/data boltcache
Docker Compose
# Start cluster
docker-compose upKubernetes
# Deploy to Kubernetes
kubectl apply -f k8s/π Documentation
π€ Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π Acknowledgments
- Inspired by Redis architecture
- Built with Go's excellent concurrency primitives
- Uses Gorilla WebSocket and Mux libraries
π Support
- π Issues: GitHub Issues
- π§ Email: mutlu@etsetra.com
- π Website: etsetra.com
- πΌ LinkedIn: Alper Mutlu ToksΓΆz
Created by Alper Mutlu ToksΓΆz with β€οΈ