Stop building your own cache layer. Start shipping features.
PodCache is a drop-in, high-performance local caching server that eliminates the need to implement custom caching solutions in your applications. Simply integrate it as a sidecar container and get enterprise-grade caching with zero development overhead.
Redis-compatible protocol means your existing Redis clients work immediately - no code changes required. When you're ready to scale, switch to Redis with a simple configuration change.
Built for containers. Optimized for microservices with multi-partition in-memory storage, automatic disk overflow, and intelligent LRU eviction. Your application gets blazing-fast local cache performance without the complexity of distributed caching.
- High Performance: Thread-safe multi-partition LRU cache with O(1) operations
- Hybrid Storage: Automatic overflow from memory to disk when capacity is exceeded
- Redis Compatible: Implements Redis RESP protocol for easy integration
- Content Addressable Storage (CAS): SHA256-based disk storage for data integrity
- Multi-Partition Architecture: Configurable partitions to reduce lock contention
- Comprehensive Logging: Detailed logging system for monitoring and debugging
- Containerization Ready: Docker support with supervisor configuration
- Signal Handling: Graceful shutdown on SIGINT/SIGTERM
PodCache uses a three-tier caching architecture:
- Memory Layer: Fast LRU caches partitioned by key hash
- Disk Layer: Content-addressable storage (CAS) for overflow data
- Protocol Layer: TCP server implementing Redis RESP protocol
- Pod Cache: Main orchestration layer managing partitions and disk overflow
- LRU Cache: In-memory hash table + doubly-linked list implementation
- CAS Registry: Content-addressable storage with SHA256-based file organization
- RESP Parser: Redis protocol parser for command processing
- TCP Server: Multi-threaded server with client connection handling
SET key value- Store a key-value pairGET key- Retrieve value by keyDEL key- Delete a keyINCR key- Increment numeric valueCLIENT- Client connection managementPING- Connection health check
- CMake 3.16 or higher
- GCC or Clang compiler
- netcat (for testing)
# Clone the repository
git clone https://github.com/mi0772/podcache.git
cd podcache
# Create build directory
mkdir -p build
cd build
# Build the project
cmake ..
make
# The binary will be available as ./podcache# Build the project (same as Linux)
cmake ..
makePodCache is configured via environment variables:
| Variable | Default | Range | Description |
|---|---|---|---|
PODCACHE_SIZE |
100 | 1-4096 | Cache size in MB |
PODCACHE_SERVER_PORT |
6379 | 1024-65535 | TCP server port |
PODCACHE_PARTITIONS |
1 | 1-64 | Number of cache partitions |
PODCACHE_FSROOT |
"./" | - | Root directory for disk storage |
# Start server with default settings (100MB cache, port 6379)
./podcache
# Start with custom configuration
PODCACHE_SIZE=256 PODCACHE_SERVER_PORT=6380 ./podcache# Using netcat for testing
echo -e '*3\r\n$3\r\nSET\r\n$5\r\nhello\r\n$5\r\nworld\r\n' | nc localhost 6379
echo -e '*2\r\n$3\r\nGET\r\n$5\r\nhello\r\n' | nc localhost 6379# PodCache is compatible with redis-cli
redis-cli -p 6379 SET mykey "Hello PodCache"
redis-cli -p 6379 GET mykeyThe project includes comprehensive test suites:
./simple_test.sh./test_disk_swap.sh./medium_test.sh# Test basic functionality
./test_logging.sh- Partitioned Storage: Keys are hashed and distributed across multiple LRU partitions
- Capacity Management: Each partition has a fixed memory capacity
- LRU Eviction: When a partition is full, least recently used items are moved to disk
- Automatic Spillover: When memory is full, tail elements are written to disk
- CAS Storage: Files are stored using SHA256-based directory structure
- Transparent Retrieval: Disk items are automatically promoted back to memory on access
- Cleanup: Promoted items are removed from disk to prevent duplication
Disk storage uses a content-addressable structure:
FSROOT/
├── ab12/
│ └── cd34/
│ └── ef56/
│ └── 7890/
│ ├── value.dat
│ └── time.dat
- Memory Operations: O(1) average time complexity
- Disk Operations: O(1) with filesystem cache
- Thread Safety: Fine-grained locking per partition
- Scalability: Linear performance scaling with partition count
PodCache provides comprehensive Docker support with pre-built base images for easy integration with microservices.
PodCache is available as a pre-built Docker base image that can be used in multi-stage builds:
# Pull the base image containing PodCache
FROM mi0772/podcache-base:latest AS podcache
# Your application stage
FROM openjdk:17-jdk-slim AS app
# ... your application setup ...
# Copy PodCache from base image
COPY --from=podcache /usr/local/bin/podcache /usr/local/bin/podcache
COPY --from=podcache /etc/podcache/ /etc/podcache/
COPY --from=podcache /etc/supervisor/conf.d/podcache.conf /etc/supervisor/conf.d/Here's a complete example of integrating PodCache with a Spring Boot microservice:
# Multi-stage build with PodCache integration
FROM mi0772/podcache-base:latest AS podcache
FROM openjdk:17-jdk-slim AS spring-app
# Install supervisor and runtime dependencies
RUN apt-get update && apt-get install -y \
supervisor \
curl \
&& rm -rf /var/lib/apt/lists/*
# Copy PodCache from base image
COPY --from=podcache /usr/local/bin/podcache /usr/local/bin/podcache
COPY --from=podcache /etc/podcache/ /etc/podcache/
COPY --from=podcache /etc/supervisor/conf.d/podcache.conf /etc/supervisor/conf.d/
# Create podcache user and directories
RUN useradd -r -s /bin/false podcache && \
mkdir -p /var/lib/podcache /var/log && \
chown podcache:podcache /var/lib/podcache
# Copy your Spring Boot application
COPY target/myapp.jar /app/app.jar
# Supervisor configuration for both services
COPY docker/supervisord-full.conf /etc/supervisor/supervisord.conf
# Health check for both services
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD curl -f http://localhost:6379/health && \
curl -f http://localhost:8080/actuator/health || exit 1
EXPOSE 8080 6379
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]The multi-service setup uses Supervisor to manage both PodCache and your application:
[supervisord]
nodaemon=true
user=root
logfile=/var/log/supervisord.log
pidfile=/var/run/supervisord.pid
[program:podcache]
command=/usr/local/bin/podcache --config /etc/podcache/podcache.conf
user=podcache
autostart=true
autorestart=true
stderr_logfile=/var/log/podcache.err.log
stdout_logfile=/var/log/podcache.out.log
priority=100
[program:spring-app]
command=java -jar /app/app.jar
user=root
autostart=true
autorestart=true
stderr_logfile=/var/log/spring.err.log
stdout_logfile=/var/log/spring.out.log
priority=200
environment=PODCACHE_HOST="localhost",PODCACHE_PORT="6379"Environment variables available in Docker containers:
| Variable | Default | Description |
|---|---|---|
PODCACHE_SIZE |
100 | Cache size in MB |
PODCACHE_SERVER_PORT |
6379 | TCP server port |
PODCACHE_PARTITIONS |
1 | Number of cache partitions |
PODCACHE_FSROOT |
"/var/lib/podcache" | Root directory for disk storage |
Example docker-compose.yml for development:
version: "3.8"
services:
app-with-cache:
build: .
ports:
- "8080:8080"
- "6379:6379"
environment:
- PODCACHE_SIZE=256
- PODCACHE_SERVER_PORT=6379
- SPRING_PROFILES_ACTIVE=docker
volumes:
- podcache_data:/var/lib/podcache
- ./logs:/var/log
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/actuator/health"]
interval: 30s
timeout: 10s
retries: 3
volumes:
podcache_data:If you need to customize PodCache, you can build your own base image:
# Build stage
FROM ubuntu:22.04 AS builder
RUN apt-get update && apt-get install -y \
build-essential cmake pkg-config
WORKDIR /app
COPY . .
RUN cmake -B build -DCMAKE_BUILD_TYPE=Release && \
cmake --build build --config Release
# Runtime stage
FROM ubuntu:22.04 AS podcache-base
RUN apt-get update && apt-get install -y \
libc6 supervisor curl ca-certificates && \
rm -rf /var/lib/apt/lists/* && \
useradd -r -s /bin/false podcache
COPY --from=builder /app/build/podcache /usr/local/bin/podcache
RUN chmod +x /usr/local/bin/podcache && \
mkdir -p /var/lib/podcache /etc/podcache /var/log && \
chown podcache:podcache /var/lib/podcache
EXPOSE 6379
CMD ["/usr/local/bin/podcache"]Example Kubernetes deployment with PodCache sidecar:
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp-with-podcache
spec:
replicas: 3
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: app
image: myapp:latest
ports:
- containerPort: 8080
env:
- name: CACHE_HOST
value: "localhost"
- name: CACHE_PORT
value: "6379"
- name: podcache
image: mi0772/podcache-base:latest
ports:
- containerPort: 6379
env:
- name: PODCACHE_SIZE
value: "512"
- name: PODCACHE_PARTITIONS
value: "4"
resources:
requests:
memory: "512Mi"
cpu: "250m"
limits:
memory: "1Gi"
cpu: "500m"- Zero Configuration: Pre-configured and ready to use
- Multi-Stage Builds: Efficient container size optimization
- Service Orchestration: Supervisor manages both cache and application
- Health Monitoring: Built-in health checks for container orchestration
- Production Ready: Optimized for containerized deployments
- Microservice Pattern: Perfect sidecar cache for distributed architectures
PodCache provides comprehensive logging with configurable levels:
- DEBUG: Detailed operation tracing
- INFO: Normal operational messages
- WARN: Warning conditions
- ERROR: Error conditions
Logs include:
- Cache operations (PUT/GET/EVICT)
- Memory usage statistics
- Disk I/O operations
- Client connections
- Server status
podcache/
├── src/ # Source code
├── include/ # Header files
├── tests/ # Test files
├── docker/ # Docker configuration
├── build/ # Build artifacts
└── cmake-build-debug/ # Debug build
main.c- Application entry pointpod_cache.c- Main cache orchestrationlru_cache.c- In-memory LRU implementationcas.c- Content-addressable storageserver_tcp.c- TCP server and protocol handlingresp_parser.c- Redis protocol parser
GNU Affero General Public License v3.0 (AGPL-3.0) - see LICENSE file for details
Carlo Di Giuseppe
Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.
- Persistence layer improvements
- Cluster support
- Advanced eviction policies
- Metrics and monitoring endpoints
- Configuration file support
- Memory-mapped file optimization