nicolasazrak / caddy-cache

Caching middleware for caddy
Mozilla Public License 2.0
110 stars 30 forks source link
cache caddy go

This project is currently unsupported and unmaintained. It was developed for caddy 1 and won't work with newer versions

caddy cache

Build Status

This is a simple caching plugin for caddy server

Notice: Although this plugin works with static content it is not advised. Static content will not see great benefits. It should be used when there are slow responses, for example when using caddy as a proxy to a slow backend.

Build

Notice: Build requires Go 1.12 or higher.

To use it you need to compile your own version of caddy with this plugin. First fetch the code

Then update the file in $GOPATH/src/github.com/caddyserver/caddy/caddy/caddymain/run.go and import _ "github.com/nicolasazrak/caddy-cache".

And finally build caddy with:

This will produce the caddy binary in that same folder. For more information about how plugins work read this doc.

Usage

Example minimal usage in Caddyfile

caddy.test {
    proxy / yourserver:5000
    cache
}

This will store in cache responses that specifically have a Cache-control, Expires or Last-Modified header set.

For more advanced usages you can use the following parameters:

caddy.test {
    proxy / yourserver:5000
    cache {
        match_path /assets
        match_header Content-Type image/jpg image/png
        status_header X-Cache-Status
        default_max_age 15m
        path /tmp/caddy-cache
    }
}

Logs

Caddy-cache adds a {cache_status} placeholder that can be used in logs.

Benchmarks

Benchmark files are in benchmark folder. Tests were run on my Lenovo G480 with Intel i3 3220 and 8gb of ram.

Todo list