Skip to content

daniel-vuky/caching-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Caching Server

A high-performance caching server written in Go. This server can cache responses to improve performance and reduce load on the origin servers.

Features

  • Response caching with configurable TTL
  • Support for GET and HEAD requests
  • Automatic cache invalidation
  • Thread-safe cache implementation
  • Cloudflare bypass capability
  • Header preservation for cached responses

Prerequisites

  • Go 1.24 or higher
  • Git

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/caching-server.git
cd caching-server
  1. Install dependencies:
go mod download
  1. Build the project:
go build -o caching-server cmd/caching-server/main.go

Configuration

Create an env.yaml file in the project root with the following structure:

server:
  port: 8080  # Port for the caching server

target:
  url: "https://example.com"  # Target URL to cache

cache:
  ttl: "1h"  # Cache TTL (e.g., "1h", "30m", "24h")

Usage

  1. Start the caching server:
./caching-server
  1. The server will start listening on the configured port (default: 8080)

  2. Access the cached content:

http://localhost:8080/your-path

Cache Headers

The server adds the following headers to responses:

  • X-Cache: Indicates if the response was served from cache
    • HIT: Response was served from cache
    • MISS: Response was fetched from origin server
  • X-Cache-TTL: Shows the remaining cache TTL

Supported HTTP Methods

  • GET: Full support with caching
  • HEAD: Full support with caching
  • Other methods: Passed through without caching

Cache Behavior

  • Responses are cached based on the request URL and method
  • Cache entries expire based on the configured TTL
  • Only successful responses (200, 301, 302, 304) are cached
  • All response headers are preserved in the cache

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Built with Go
  • Uses Viper for configuration management

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages