Download the PHP package wedevelopnl/silverstripe-fpc-purge without Composer
On this page you can find all versions of the php package wedevelopnl/silverstripe-fpc-purge. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wedevelopnl/silverstripe-fpc-purge
More information about wedevelopnl/silverstripe-fpc-purge
Files in wedevelopnl/silverstripe-fpc-purge
Informations about the package silverstripe-fpc-purge
silverstripe-fpc-purge
This module adds some cache purging capabilities to the website, to support FPC in nginx or apache.
Requirements
- See
composer.json
requirements - nginx with Lua module
Installation
composer require wedevelopnl/silverstripe-fpc-purge
Configuring nginx
Install the latest version of ngx_cache_purge.
Then update your server configuration:
NOTE: Consider randomizing or otherwise protecting your URL to prevent abuse.
Configuring the module
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.
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, or use the extension included in this module for an easier foolproof implementation.
Now you have to add a updateCacheControl()
method to your PageController and configure the CacheControl headers.
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.
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
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.
- SilverStripe will overrule our cache control headers when a session is active.
- The nginx configuration triggers a bypass when a PHPSESSID is found.
Default configuration
License
See License
Maintainers
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 document for more information.
Getting started
We advise to use Docker/Docker compose for development.\ We also included a Makefile to simplify some commands
Our development container contains some built-in tools like PHPCSFixer
.
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
You can run make help
to get a list with all available make
commands.