Skip to content

🔧 Caddy anonymous cache plugin for MediaWiki

License

Notifications You must be signed in to change notification settings

femiwiki/caddy-mwcache

Repository files navigation

caddy-mwcache

go doc badge Github checks status codecov.io status

caddy-mwcache is a cache plugin for MediaWiki.

Usage

example.com {
    mwcache
}

Currently, only "ristretto" backend is supported and used by default.

# Default value
mwcache {
    ristretto
    purge_acl 127.0.0.1
}
  • ristretto is also used as a block to configure backend. Configuration keys are snake case versions of fields of Ristretto's Config struct. But it is limited to only primitive types(bool, int, string, etc).
  • purge_acl is either a single item or a list of CIDRs or IP addresses that are allowed to request to purge cache.
mwcache {
    ristretto {
        num_counters <value>
        max_cost <value>
        buffer_items <value>
        <additional config key1> <value1>
        <additional config key2> <value2>
    }
    purge_acl {
        <cidr1>
        <cidr2>
        <address1>
        <address2>
    }
}

Configuring MediaWiki

WARNING: If you are using php-curl extension with curl ≥7.62, you cannot use this plugin due to MediaWiki's bug T264735.

You must add the next lines your LocalSettings.php.

// LocalSettings.php
$wgUseCdn = true;
$wgCdnServers = '127.0.0.1';
// If your web server supports TLS
$wgInternalServer = 'http://127.0.0.1';

Build

Prerequisites:

# Run the program right away
xcaddy
xcaddy version
xcaddy list-modules

# Build the binary, "./caddy" is the output
xcaddy build \
  --with github.com/femiwiki/caddy-mwcache

Development

Use docker-compose to setup test environment.

# Start a php-fpm server
docker-compose --project-directory example up --detach
# Start a web server
docker-compose --project-directory example exec --workdir=/root/src caddy xcaddy start --config example/Caddyfile
# Or detach by run command
# docker-compose --project-directory example exec --workdir=/root/src caddy xcaddy run --config example/Caddyfile

# Test
curl -so /dev/null -w "%{time_total}\n" 'http://127.0.0.1:2015'
curl -so /dev/null -w "%{time_total}\n" 'http://127.0.0.1:2015/slow.php'
curl -so /dev/null -w "%{time_total}\n" 'http://127.0.0.1:2015/slow.php'

# Reload Caddyfile
docker-compose --project-directory example exec --workdir=/root/src caddy xcaddy reload --config example/Caddyfile

# Stop the web server
docker-compose --project-directory example exec --workdir=/root/src caddy xcaddy stop

# Stop the all services
docker-compose --project-directory example down

 


The source code of femiwiki/caddy-mwcache is primarily distributed under the terms of the GNU Affero General Public License v3.0 or any later version. See COPYRIGHT for details.