All Projects → nicolasazrak → Caddy Cache

nicolasazrak / Caddy Cache

Licence: mpl-2.0
Caching middleware for caddy

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Caddy Cache

souin
An HTTP cache system, RFC compliant, compatible with @TykTechnologies, @traefik, @caddyserver, @go-chi, @bnkamalesh, @beego, @devfeel, @labstack, @gofiber, @go-goyave, @gin-gonic, @zalando, @zeromicro, @nginx and @apache
Stars: ✭ 269 (+149.07%)
Mutual labels:  cache, caddy
Gcache
An in-memory cache library for golang. It supports multiple eviction policies: LRU, LFU, ARC
Stars: ✭ 1,787 (+1554.63%)
Mutual labels:  cache
Wfpc
Magento full page cache warmer
Stars: ✭ 95 (-12.04%)
Mutual labels:  cache
Fast React Render
[DEPRECATED] Use last versions of React and Node.js for better performance
Stars: ✭ 102 (-5.56%)
Mutual labels:  cache
Vmtouch
Portable file system cache diagnostics and control
Stars: ✭ 1,341 (+1141.67%)
Mutual labels:  cache
Deta cache
缓存cache服务器
Stars: ✭ 106 (-1.85%)
Mutual labels:  cache
Drone Volume Cache
Drone plugin for caching to a locally mounted volume
Stars: ✭ 93 (-13.89%)
Mutual labels:  cache
Redis
Async Redis Client for PHP based on Amp.
Stars: ✭ 107 (-0.93%)
Mutual labels:  cache
Ymate Platform V2
YMP是一个非常简单、易用的轻量级Java应用开发框架,涵盖AOP、IoC、WebMVC、ORM、Validation、Plugin、Serv、Cache等特性,让开发工作像搭积木一样轻松!
Stars: ✭ 106 (-1.85%)
Mutual labels:  cache
Bojack
🐴 The unreliable key-value store
Stars: ✭ 101 (-6.48%)
Mutual labels:  cache
Fastapi cache
FastAPI simple cache
Stars: ✭ 96 (-11.11%)
Mutual labels:  cache
Medialoader
Cache video/audio while playing for any android media player
Stars: ✭ 97 (-10.19%)
Mutual labels:  cache
Node Cache
a node internal (in-memory) caching module
Stars: ✭ 1,660 (+1437.04%)
Mutual labels:  cache
Egocache
Fast Caching for Objective-C (iPhone & Mac Compatible)
Stars: ✭ 1,339 (+1139.81%)
Mutual labels:  cache
Laravel Cacheable
Rinvex Cacheable is a granular, intuitive, and fluent caching system for eloquent models. Simple, but yet powerful, plug-n-play with no hassle.
Stars: ✭ 107 (-0.93%)
Mutual labels:  cache
Api Restful Con Laravel Guia Definitiva
Repositorio para el código base del curso "API RESTful con Laravel - Guía Definitiva"
Stars: ✭ 95 (-12.04%)
Mutual labels:  cache
Memoize
A method caching macro for elixir using CAS on ETS.
Stars: ✭ 100 (-7.41%)
Mutual labels:  cache
Wikipediap2p
WikipediaP2P.org Chrome Extension
Stars: ✭ 105 (-2.78%)
Mutual labels:  cache
Keyv
Simple key-value storage with support for multiple backends
Stars: ✭ 1,629 (+1408.33%)
Mutual labels:  cache
Caddy Jwt
JWT middleware for the Caddy server
Stars: ✭ 107 (-0.93%)
Mutual labels:  caddy

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

  • export GO111MODULE=on
  • go get -u github.com/caddyserver/caddy/...
  • go get -u github.com/nicolasazrak/caddy-cache/...

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:

  • cd $GOPATH/src/github.com/caddyserver/caddy/caddy
  • ./build.bash

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:

  • 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.
  • 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.
  • path: Path where to store the cached responses. By default it will use the operating system temp folder.
  • default_max_age: Max-age to use for matched responses that do not have an explicit expiration. (Default: 5 minutes)
  • 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)
  • cache_key: Configures the cache key using Placeholders, it supports any of the request placeholders. (Default: {method} {host}{path}?{query})
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.

  • 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).

    wrk -c 400 -d 30s --latency -t 4 http://caddy.test:2015/sherlock.txt

    Req/s Throughput 99th Latency
    proxy + cache 4548.03 2.64 GB/s 561.39 ms
    proxy 1043.61 619.65 MB/s 1.00 s
    root 3668.14 2.13 GB/s 612.39 ms
  • 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).

    wrk -c 400 -d 30s --latency -t 4 http://caddy.test:2015/montecristo.txt

    Req/s Throughput 99th Latency
    proxy + cache 1199.81 3.01 GB/s 1.65 s
    proxy 473.14 1.20 GB/s 1.81 s
    root 1064.44 2.66 GB/s 1.71 s
  • Third test: Download pg31674.txt (41 Kb) a root server (caddy.test5) with gzip and a proxy to root server with cache (caddy.test4).

    wrk -c 50 -d 30s --latency -H 'Accept-Encoding: gzip' -t 4 http://caddy.test4:2015/pg31674.txt

    Req/s Throughput 99th Latency
    proxy + cache 16547.84 242.05 MB/s 22.48ms
    root 792.08 11.60 MB/s 109.98ms

Todo list

  • [x] Support vary header
  • [x] Add header with cache status
  • [x] Stream responses while fetching them from upstream
  • [x] Locking concurrent requests to the same path
  • [x] File disk storage for larger objects
  • [x] Add a configuration to not use query params in cache key (via cache_key directive)
  • [ ] Purge cache entries #1
  • [ ] Serve stale content if proxy is down
  • [ ] Punch hole cache
  • [ ] Do conditional requests to revalidate data
  • [ ] Max entries size
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].