{"id":13581923,"url":"https://github.com/nicolasazrak/caddy-cache","last_synced_at":"2025-04-06T10:33:05.966Z","repository":{"id":57480701,"uuid":"70363798","full_name":"nicolasazrak/caddy-cache","owner":"nicolasazrak","description":"Caching middleware for caddy","archived":true,"fork":false,"pushed_at":"2021-04-18T15:20:08.000Z","size":1383,"stargazers_count":109,"open_issues_count":20,"forks_count":30,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-11-05T21:45:25.876Z","etag":null,"topics":["cache","caddy","go"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nicolasazrak.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-08T23:52:09.000Z","updated_at":"2024-11-05T00:08:37.000Z","dependencies_parsed_at":"2022-09-26T17:41:19.925Z","dependency_job_id":null,"html_url":"https://github.com/nicolasazrak/caddy-cache","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicolasazrak%2Fcaddy-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicolasazrak%2Fcaddy-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicolasazrak%2Fcaddy-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicolasazrak%2Fcaddy-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nicolasazrak","download_url":"https://codeload.github.com/nicolasazrak/caddy-cache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247470545,"owners_count":20944146,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","caddy","go"],"created_at":"2024-08-01T15:02:19.350Z","updated_at":"2025-04-06T10:33:04.313Z","avatar_url":"https://github.com/nicolasazrak.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"## This project is currently unsupported and unmaintained. It was developed for caddy 1 and won't work with newer versions\n\n\n# caddy cache\n\n[![Build Status](https://travis-ci.org/nicolasazrak/caddy-cache.svg?branch=master)](https://travis-ci.org/nicolasazrak/caddy-cache)\n\nThis is a simple caching plugin for [caddy server](https://caddyserver.com/)\n\n**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.\n\n## Build\n\n**Notice:** Build requires Go 1.12 or higher.\n\nTo use it you need to compile your own version of caddy with this plugin. First fetch the code\n\n- `export GO111MODULE=on`\n- `go get -u github.com/caddyserver/caddy/...`\n- `go get -u github.com/nicolasazrak/caddy-cache/...`\n\nThen update the file in `$GOPATH/src/github.com/caddyserver/caddy/caddy/caddymain/run.go` and import `_ \"github.com/nicolasazrak/caddy-cache\"`.\n\nAnd finally build caddy with:\n\n- `cd $GOPATH/src/github.com/caddyserver/caddy/caddy`\n- `./build.bash`\n\nThis will produce the caddy binary in that same folder. For more information about how plugins work read [this doc](https://github.com/caddyserver/caddy/wiki/Writing-a-Plugin:-Directives). \n\n## Usage\n\nExample minimal usage in `Caddyfile`\n\n```\ncaddy.test {\n    proxy / yourserver:5000\n    cache\n}\n```\n\nThis will store in cache responses that specifically have a `Cache-control`, `Expires` or `Last-Modified` header set.\n\nFor more advanced usages you can use the following parameters: \n\n- `match_path`: Paths to cache. For example `match_path /assets` will cache all successful responses for requests that start with /assets and are not marked as private.\n- `match_header`: Matches responses that have the selected headers. For example `match_header Content-Type image/png image/jpg` will cache all successful responses that with content type `image/png` OR `image/jpg`. Note that if more than one is specified, anyone that matches will make the response cacheable. \n- `path`: Path where to store the cached responses. By default it will use the operating system temp folder.\n- `default_max_age`: Max-age to use for matched responses that do not have an explicit expiration. (Default: 5 minutes)\n- `status_header`: Sets a header to add to the response indicating the status. It will respond with: skip, miss or hit. (Default: `X-Cache-Status`)\n- `cache_key`: Configures the cache key using [Placeholders](https://caddyserver.com/docs/placeholders), it supports any of the request placeholders. (Default: `{method} {host}{path}?{query}`)\n\n```\ncaddy.test {\n    proxy / yourserver:5000\n    cache {\n        match_path /assets\n        match_header Content-Type image/jpg image/png\n        status_header X-Cache-Status\n        default_max_age 15m\n        path /tmp/caddy-cache\n    }\n}\n```\n\n\n### Logs\n\nCaddy-cache adds a `{cache_status}` placeholder that can be used in logs.\n\n## Benchmarks\n\nBenchmark files are in `benchmark` folder. Tests were run on my Lenovo G480 with Intel i3 3220 and 8gb of ram.\n\n- First test: Download `sherlock.txt` (608 Kb) file from the root (caddy.test3), a proxy to root server (caddy.test2) and a proxy to root server with cache (caddy.test).\n\n    `wrk -c 400 -d 30s --latency -t 4 http://caddy.test:2015/sherlock.txt`\n\n    |               | Req/s   | Throughput  | 99th Latency |\n    |---------------|---------|-------------|--------------|\n    | proxy + cache | 4548.03 |   2.64 GB/s | 561.39 ms    |\n    | proxy         | 1043.61 | 619.65 MB/s |   1.00 s     |\n    | root          | 3668.14 |   2.13 GB/s | 612.39 ms    |\n\n- Second test: Download `montecristo.txt` (2,6 Mb) file from the root (caddy.test3), a proxy to root server (caddy.test2) and a proxy to root server with cache (caddy.test).\n\n    `wrk -c 400 -d 30s --latency -t 4 http://caddy.test:2015/montecristo.txt`\n\n    |               | Req/s   | Throughput  | 99th Latency |\n    |---------------|---------|-------------|--------------|\n    | proxy + cache | 1199.81 |   3.01 GB/s | 1.65 s       |\n    | proxy         |  473.14 |   1.20 GB/s | 1.81 s       |\n    | root          | 1064.44 |   2.66 GB/s | 1.71 s       |\n\n- Third test: Download `pg31674.txt` (41 Kb) a root server (caddy.test5) with gzip and a proxy to root server with cache (caddy.test4).\n\n    `wrk -c 50 -d 30s --latency -H 'Accept-Encoding: gzip' -t 4 http://caddy.test4:2015/pg31674.txt`\n\n    |               | Req/s    | Throughput  | 99th Latency |\n    |---------------|----------|-------------|--------------|\n    | proxy + cache | 16547.84 | 242.05 MB/s |  22.48ms     |\n    | root          | 792.08   |  11.60 MB/s | 109.98ms     |\n\n## Todo list\n\n- [x] Support `vary` header\n- [x] Add header with cache status\n- [x] Stream responses while fetching them from upstream\n- [x] Locking concurrent requests to the same path\n- [x] File disk storage for larger objects\n- [x] Add a configuration to not use query params in cache key (via `cache_key` directive)\n- [ ] Purge cache entries [#1](https://github.com/nicolasazrak/caddy-cache/issues/1)\n- [ ] Serve stale content if proxy is down\n- [ ] Punch hole cache\n- [ ] Do conditional requests to revalidate data\n- [ ] Max entries size\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicolasazrak%2Fcaddy-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnicolasazrak%2Fcaddy-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicolasazrak%2Fcaddy-cache/lists"}