A high-performance caching server written in Go. This server can cache responses to improve performance and reduce load on the origin servers.
- 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
- Go 1.24 or higher
- Git
- Clone the repository:
git clone https://github.com/yourusername/caching-server.git
cd caching-server- Install dependencies:
go mod download- Build the project:
go build -o caching-server cmd/caching-server/main.goCreate 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")- Start the caching server:
./caching-server-
The server will start listening on the configured port (default: 8080)
-
Access the cached content:
http://localhost:8080/your-path
The server adds the following headers to responses:
X-Cache: Indicates if the response was served from cacheHIT: Response was served from cacheMISS: Response was fetched from origin server
X-Cache-TTL: Shows the remaining cache TTL
- GET: Full support with caching
- HEAD: Full support with caching
- Other methods: Passed through without caching
- 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
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.