Caddy
Disclaimer
github.com/darkweak/souin/plugin/caddy
and github.com/caddyserver/cache-handler
are mainly the same but the souin/plugin/caddy
is the development repository and the cache-handler
is the stable version. They both contain the features and suport the configuration below but on the Souin repository you’ll get access to new features/RFCs at early stage with faster bug fixes.
Usage
Build your caddy binary
We assume that you already installed the xcaddy
binary on your device. If not, you can refer to the documentation here
You should get a new caddy
executable file in your current directory.
Run your HTTP cache
We need to tell caddy that it must use the HTTP cache with the cache
global and handler directives. You can set your configuration globally and override it in each handlers.
Configuration
Every configuration directives can be used either in the global or in the handler blocks.
Basic configuration
Usually we set the ttl
, the stale
and the default_cache_control
directives in the global configuration.
But we can go further by enabling the Souin API and enable the debug
, prometheus
, souin
endpoints
With this given configuration if you go on https://localhost:2019/souin-api/souin we get the stored keys list.
If we go on https://localhost:2019/souin-api/metrics we access to the prometheus web page.
If we go on https://localhost:2019/souin-api/debug/ we access to the pprof web page.
Complex configuration
Storages
Since v1.7.0
Souin implements only an in-memory storage, if you need a specific storage you have to take it from the storages repository and add to your build command.
(e.g. with otter using caddy) You have to build your caddy module with the desired storage
and configure otter in your Caddyfile/JSON configuration file.
See the storages page to learn more about each supported storage.
First you have to build Caddy with Souin and a storage using the following template.
You can also use as many storages you want.
We can define multiple storages to use to store the response from the upstream server and specify the order.
Here, we define 3 storages badger
, nuts
and redis
and nuts
will be accessed first, badger
the second and redis
the third only if the previous doesn’t return suitable data.
Indeed you can configure each storage with the path
or url
directive (depending the provider) but also with the configuration
directive. That’s a simple key - value
that are defined by the library used to implement each provider.