https://github.com/alleyinteractive/wp-404-caching
Enables caching on 404 pages to prevent performance issues related to bad request flooding.
https://github.com/alleyinteractive/wp-404-caching
wordpress wordpress-plugin
Last synced: about 1 year ago
JSON representation
Enables caching on 404 pages to prevent performance issues related to bad request flooding.
- Host: GitHub
- URL: https://github.com/alleyinteractive/wp-404-caching
- Owner: alleyinteractive
- License: gpl-2.0
- Created: 2024-03-07T16:59:09.000Z (over 2 years ago)
- Default Branch: develop
- Last Pushed: 2025-03-01T06:08:30.000Z (over 1 year ago)
- Last Synced: 2025-03-30T19:01:52.162Z (about 1 year ago)
- Topics: wordpress, wordpress-plugin
- Language: PHP
- Homepage:
- Size: 15.4 MB
- Stars: 8
- Watchers: 19
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# WP 404 Caching
[](https://github.com/alleyinteractive/wp-404-caching/actions/workflows/all-pr-tests.yml)
A WordPress plugin to provide full page caching for 404 pages, improving performance and reducing server load.
## Requirements
- SSL enabled on the website.
- An external object cache setup (e.g., Redis, Memcached).
- Requires at least: 6.3
- Tested up to: 6.4
- Requires PHP: 8.1
- License: GPL v2 or later
## Description
WP 404 Caching is a lightweight plugin that efficiently serves cached 404 pages to non-logged-in users. It reduces server load by storing the cached 404 page in an external object cache and returning it early in the request process.
The plugin uses a dual regular/stale caching strategy to minimize cache misses. It maintains a regular cache with a 1-hour expiration and a stale cache with a 1-day expiration. If the regular cache is empty, the stale cache is served.
## Features
- Full page caching for 404 pages
- Utilizes external object cache for storing cached 404 pages
- Dual regular/stale caching strategy to minimize cache misses
- Automatically generates and caches 404 page via a "guaranteed 404 URI"
- Triggers cache generation hourly via a cron job and immediately on cache misses
- Sends `X-WP-404-Cache` header to indicate cache HIT/MISS status
- Ensures compatibility with analytics by replacing the "guaranteed 404 URI" with the actual requested URI in the cached page
## Installation
### Via Composer (recommeded):
You can install the package via composer:
```bash
composer require alleyinteractive/wp-404-caching
```
### Manual install:
1. Upload the `wp-404-caching` directory to your `/wp-content/plugins/` directory.
2. Activate the plugin through the 'Plugins' menu in WordPress.
## Usage
The plugin works out of the box with default settings. You can customize the cache expiration times by modifying the `CACHE_TIME` and `STALE_CACHE_TIME` constants in the `Full_Page_Cache_404` class.
Activate the plugin in WordPress and use it like so:
```php
add_filter( 'wp_404_caching_cache_time', function( $cache_time ) {
return 2 * HOUR_IN_SECONDS; // Set cache time to 2 hours.
} );
add_filter( 'wp_404_caching_stale_cache_time', function( $stale_cache_time ) {
return 2 * DAY_IN_SECONDS; // Set stale cache time to 2 days.
} );
// Programmatically bypass the cache.
add_filter( 'wp_404_caching_enabled', '__return_false' );
```
## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Credits
This project is actively maintained by [Alley
Interactive](https://github.com/alleyinteractive). Like what you see? [Come work
with us](https://alley.co/careers/).
- [Alley](https://github.com/Alley)
## License
The GNU General Public License (GPL) license. Please see [License File](LICENSE) for more information.
---
# Developer Notes
## Testing
Run `composer test` to run tests against PHPUnit and the PHP code in the plugin.