mwcache

package module
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 16, 2021 License: AGPL-3.0 Imports: 21 Imported by: 0

README

caddy-mwcache go doc badge Github checks status codecov.io status

⚠️ Work-in-progress - See milestones for v1.0.0

caddy-mwcache is a cache plugin for MediaWiki.

Usage

NOTE: You cannot use this plugin if the next conditions match:

  • MediaWiki < v1.36
  • php-curl extension installed
  • curl >= v7.62

See https://phabricator.wikimedia.org/T264735 for further details.

mwcache {
  [<backend>]
  [ristretto {
    num_counters <value>
	  max_cost <value>
	  buffer_items <value>
    <additional config key1> <value1>
    <additional config key2> <value2>
  }]
  [badger {
    <badger option key1> <badger option value1>
    <badger option key2> <badger option value2>
  }]
  [purge_acl 127.0.0.1]
  [purge_acl {
    <address1>
    <...>
  }]
  • backend is either ristretto, badger, or map(experimental). Default to ristretto.
  • ristretto and badger are also used as a block to configure backend. Configuration keys are snake case versions of fields of Ristretto's Config struct or Badger's Options struct. But it is limited to only primitive types(bool, int, string).
  • purge_acl is either a list of acl or a ip address that are allowed to request to purge cache.

You must add the next lines your LocalSettings.php.

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

Prerequisites:

xcaddy build

# ./caddy is the output
Development

Prerequisites:

# 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.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrKeyNotFound = errors.New("Key not found")
)

Functions

func CIDRContainsIP

func CIDRContainsIP(cidr string, needleStr string) bool

func ValidateBadgerConfig

func ValidateBadgerConfig(rawOptions map[string]string) error

func ValidateRistrettoConfig

func ValidateRistrettoConfig(rawOptions map[string]string) error

TODO

Types

type Backend

type Backend interface {
	// contains filtered or unexported methods
}

type BadgerBackend

type BadgerBackend struct {
	// contains filtered or unexported fields
}

type Config

type Config struct {
	Backend         string            `json:"backend,omitempty"`
	PurgeAcl        []string          `json:"purge_acl,omitempty"`
	BadgerConfig    map[string]string `json:"badger_config,omitempty"`
	RistrettoConfig map[string]string `json:"ristretto_config,omitempty"`
}

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

func (Handler) CaddyModule

func (Handler) CaddyModule() caddy.ModuleInfo

CaddyModule implements caddy.Module

func (*Handler) Provision

func (h *Handler) Provision(ctx caddy.Context) error

Provision implements caddy.Provisioner.

func (Handler) ServeHTTP

func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error

ServeHTTP implements caddyhttp.MiddlewareHandler.

func (*Handler) UnmarshalCaddyfile

func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

func (*Handler) Validate

func (h *Handler) Validate() error

Validate implements caddy.Validator.

type MapBackend

type MapBackend struct {
	// contains filtered or unexported fields
}

type RistrettoBackend

type RistrettoBackend struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL