PHPackages                             wedevelopnl/silverstripe-fpc-purge - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. wedevelopnl/silverstripe-fpc-purge

ActiveLibrary[Caching](/categories/caching)

wedevelopnl/silverstripe-fpc-purge
==================================

FPC purge module

1.0.0-rc4(3y ago)0197MITPHPPHP &gt;=7.4

Since Jan 1Pushed 3y ago5 watchersCompare

[ Source](https://github.com/wedevelopnl/silverstripe-fpc-purge)[ Packagist](https://packagist.org/packages/wedevelopnl/silverstripe-fpc-purge)[ RSS](/packages/wedevelopnl-silverstripe-fpc-purge/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (4)Dependencies (2)Versions (5)Used By (0)

silverstripe-fpc-purge
======================

[](#silverstripe-fpc-purge)

This module adds some cache purging capabilities to the website, to support FPC in nginx or apache.

Requirements
------------

[](#requirements)

- See `composer.json` requirements
- nginx with Lua module

Installation
------------

[](#installation)

- `composer require wedevelopnl/silverstripe-fpc-purge`

### Configuring nginx

[](#configuring-nginx)

Install the latest version of [ngx\_cache\_purge](https://github.com/nginx-modules/ngx_cache_purge).

Then update your server configuration:

```
fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=fastcgicache:100m max_size=5g inactive=60m use_temp_path=off;
fastcgi_cache_key "$scheme$request_method$host$request_uri";

server {
    location = /purge-cache {
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        fastcgi_cache fastcgicache;
        fastcgi_cache_purge PURGE purge_all from 127.0.0.1;
        cache_purge_response_type text;
    }

    location /index.php {
        fastcgi_buffer_size 32k;
        fastcgi_busy_buffers_size 64k;
        fastcgi_buffers 4 32k;
        fastcgi_keep_conn on;
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;

        # fastcgi caching
        fastcgi_cache fastcgicache;
        fastcgi_cache_valid 200 301 302 60m;
        fastcgi_cache_use_stale error timeout updating invalid_header http_500 http_503;
        fastcgi_cache_min_uses 1;
        fastcgi_cache_lock on;
        fastcgi_no_cache $cookie_PHPSESSID;
        fastcgi_cache_bypass $cookie_PHPSESSID;
        fastcgi_ignore_headers Set-Cookie;

        add_header X-Cache $upstream_cache_status;
    }

    # ...
}

```

**NOTE:** Consider randomizing or otherwise protecting your URL to prevent abuse.

### Configuring the module

[](#configuring-the-module)

```
---
Name: 'fpc-purge-config'
Only:
  environment: 'live'
---
WeDevelop\FPCPurge\FPCPurgeConfig:
  enabled: true
  endpoints:
    # Purging locally over HTTP
    - host: localhost:80
      method: PURGE
      path: /purge-cache
    # Purging locally over HTTPS
    - host: tls://localhost:443
      http_host: example.com # Required to tell nginx or apache what virtual host you want to connect to
      method: PURGE
      path: /purge-cache
    # Purging externally over HTTPS
    - host: tls://example.com:443
      method: PURGE
      path: /purge-cache
    # Purging a specific server (useful when load balancing and purging all servers)
    - host: tls://10.0.0.5:443
      http_host: example.com # Required to tell nginx or apache what virtual host you want to connect to
      method: PURGE
      path: /purge-cache

Page:
  extensions:
    - WeDevelop\FPCPurge\Extensions\FPCPurgeExtension
```

Here you can enable the module and configure the endpoint used to purge.

You can test this configuration by going into the SilverStripe admin, then click FPC Purge in the sidebar and click the Purge Cache button. It should tell you if it was successful.

We also add an extension to Page to purge the cache after publishing a page.

**NOTE:** The purge after publishing opens a connection, then sends a non-blocking request, should have little to no impact on publishing performance depending on the endpoints.

If you're using dnadesign/silverstripe-elemental don't forget to also apply the extension on BaseElement to make sure cache is purged after publishing an element.

```
DNADesign\Elemental\Models\BaseElement:
  extensions:
    - WeDevelop\FPCPurge\Extensions\FPCPurgeExtension
```

### Setting up Cache Control

[](#setting-up-cache-control)

All of the above will not cache anything until you setup cache control. You can either follow the [official SilverStripe docs](https://docs.silverstripe.org/en/4/developer_guides/performance/http_cache_headers/), or use the extension included in this module for an easier foolproof implementation.

```
PageController:
    extensions:
        - WeDevelop\FPCPurge\Extensions\FPCPurgeControllerExtension
```

Now you have to add a `updateCacheControl()` method to your PageController and configure the CacheControl headers.

```
public function updateCacheControl(): void
{
    HTTPCacheControlMiddleware::singleton()
        ->enableCache()
        ->setSharedMaxAge(3600)
        ->setMaxAge(60);
}
```

**Shared Max Age:** the amount of time in seconds this page is allowed to be cached in your FPC (nginx, apache, etc.)
**Max Age:** the amount of time in seconds this page is allowed to be cached in the browser

If you have another controller that extends the PageController but serves more dynamic data from an API for example, you can override the CacheControl headers in that controller by overriding the updateCacheControl method.

```
public function updateCacheControl(): void
{
    HTTPCacheControlMiddleware::singleton()
        ->enableCache()
        ->setSharedMaxAge(600)
        ->setMaxAge(0);
}
```

Here we set the max age to 0 to prevent it from being cached by the browser, and a relatively low shared max age. This way cache can only be stale for 10 minutes.

### Sessions and CSRF tokens

[](#sessions-and-csrf-tokens)

It's important not to cache pages that are generated within the context of a session, for example a logged in user or a CSRF token. Luckily, there are two things protecting us from this mistake.

1. SilverStripe will overrule our cache control headers when a session is active.
2. The nginx configuration triggers a bypass when a PHPSESSID is found.

Default configuration
---------------------

[](#default-configuration)

```
WeDevelop\FPCPurge\FPCPurgeConfig:
  enabled: false
  endpoints: []
```

License
-------

[](#license)

See [License](LICENSE)

Maintainers
-----------

[](#maintainers)

- [WeDevelop](https://www.wedevelop.nl/)

Development and contribution
----------------------------

[](#development-and-contribution)

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. See read our [contributing](CONTRIBUTING.md) document for more information.

### Getting started

[](#getting-started)

We advise to use [Docker](https://docker.com)/[Docker compose](https://docs.docker.com/compose/) for development.
We also included a [Makefile](https://www.gnu.org/software/make/) to simplify some commands

Our development container contains some built-in tools like `PHPCSFixer`.

#### Getting development container up

[](#getting-development-container-up)

`make build` to build the Docker container and then run detached.
If you want to only get the container up, you can simply type `make up`.

You can SSH into the container using `make sh`.

#### All make commands

[](#all-make-commands)

You can run `make help` to get a list with all available `make` commands.

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

1271d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7a41b16aafbe795cfad0b4941b9ac37305e5bba2aefbcf56cc1f0c180928de27?d=identicon)[WeDevelop](/maintainers/WeDevelop)

---

Tags

silverstripecachepurgefpc

###  Code Quality

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/wedevelopnl-silverstripe-fpc-purge/health.svg)

```
[![Health](https://phpackages.com/badges/wedevelopnl-silverstripe-fpc-purge/health.svg)](https://phpackages.com/packages/wedevelopnl-silverstripe-fpc-purge)
```

###  Alternatives

[silverstripe/staticpublishqueue

Static publishing queue to create static versions of pages for enhanced performance and security

44138.6k6](/packages/silverstripe-staticpublishqueue)[tractorcow/silverstripe-dynamiccache

FORK OF Silverstripe module for simple on the fly caching of dynamic content

3816.0k2](/packages/tractorcow-silverstripe-dynamiccache)[steadlane/silverstripe-cloudflare

This module aims to relieve the stress of using Cloudflare caching with any SilverStripe project. Adds extension hooks that clears Cloudflare's cache for a specific page when that page is published or unpublished.

233.7k](/packages/steadlane-silverstripe-cloudflare)[silverstripe-terraformers/keys-for-cache

Silverstripe cache key management

1628.5k](/packages/silverstripe-terraformers-keys-for-cache)[silverstripe-australia/simplecache

Simple(r) caching abstraction layer, with a static publisher that will use that cache layer for storage

146.8k](/packages/silverstripe-australia-simplecache)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
