Skip to content

itsbaam/CacheCruiser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CacheCruiser

A CLI caching proxy server.

Overview

CacheCruiser forwards incoming HTTP requests to a specified origin server, caches the responses on the cache instance, and returns cached responses on repeat requests to improve performance and reduce load on the origin.

This project currently implements in-memory caching and disk caching. Redis caching is planned for future releases.

Prerequisites

  • Go 1.18+ installed
  • Internet connectivity

Installation

  1. Clone the repository:
    git clone https://github.com/yourusername/cachecruiser.git
    cd cachecruiser
  2. Build the binary:
    go build -o cachecruiser cmd/proxy-server/main.go

Usage

./cachecruiser --port <port> --origin <origin-url>

Flags

  • --port <number>: Port on which CacheCruiser listens (required)
  • --origin <url>: URL of the origin server to which requests are forwarded (required)
  • --clear-cache: Remove all cached data and exit (optional)
  • --cache-type <type>: Type of cache to use (optional, default: memory)
  • --cache-dir <path>: Directory to store cached data (optional, default: ./disk-cache-data)

Examples

# Start the proxy on port 3000, forwarding to dummyjson.com
./cachecruiser --port 3000 --origin http://dummyjson.com

# Start the proxy with disk caching, storing cache data in a custom directory
./cachecruiser --port 3000 --origin http://dummyjson.com --cache-type disk --cache-dir /path/to/cache/data

# Start the proxy with disk caching using default cache directory
./cachecruiser --port 3000 --origin http://dummyjson.com --cache-type disk

# Clear the cache and exit
./cachecruiser --clear-cache

Cache Behavior

  • On first request to a given path, CacheCruiser forwards to the origin, returns the response with header:
    X-Cache: MISS
    
  • On subsequent requests to the same URL, CacheCruiser serves the cached response with header:
    X-Cache: HIT
    

CacheCruiser makes it easy to speed up repeat requests by transparently caching responses — no configuration beyond port and origin needed.

Technical Details

Caching Behavior

  • Only GET requests are cached
  • Cache keys are generated using request method + URL
  • Thread-safe implementation using read-write mutexes
  • Support for time-based expiration of cache entries

Architecture

CacheCruiser is built with a modular design:

  • Cache interface that can be implemented by different storages (in-memory, disk, Redis, etc.)
  • MemoryCache implementation for in-memory storage
  • ProxyServer for handling HTTP requests and responses

Development

This project is a learning exercise that comes from Roadmap.sh Caching Proxy project.

Testing

Not implemented. May come in future iterations also as a learning exercise.

Roadmap

  • In-memory caching
  • Disk-based caching
  • Redis-based caching
  • Configurable cache TTL via command-line flags
  • Cache size limits and eviction policies
  • Cache invalidation endpoints
  • Tests

Disclaimer

As this project is a learning exercise, the features listed in the roadmap may or may not be implemented in the future.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages