Download the PHP package ryanhellyer/stale-cache without Composer
On this page you can find all versions of the php package ryanhellyer/stale-cache. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ryanhellyer/stale-cache
More information about ryanhellyer/stale-cache
Files in ryanhellyer/stale-cache
Package stale-cache
Short Description A PHP implementation of the stale-while-revalidate caching pattern for WordPress
License GPL-2.0-or-later
Informations about the package stale-cache
StaleCache
A PHP implementation of the stale-while-revalidate caching pattern for WordPress, designed to improve performance and reduce load on expensive operations.
Inspired by the recent implementation of Cache::flexible()
in Laravel.
Features
- Stale-While-Revalidate Pattern: Serves stale content while asynchronously refreshing cache in the background
- Race Condition Prevention: Uses locking mechanism to prevent multiple simultaneous cache updates
- WordPress Integration: Built on WordPress transients for reliable cache storage
- Async Updates: Leverages FastCGI finish request for non-blocking cache updates (for when using PHP-FPM)
- Type Safety: Written in strict PHP with full type declarations
Installation
Usage
Basic usage example:
Configuration Parameters
- Stale Time: How long the cache is considered fresh (in seconds)
- Cache Duration: Total time to keep the cache (in seconds)
- Lock Duration: How long to hold the refresh lock (defaults to 1 hour)
Cache States
The cache can be in one of three states:
- Fresh: Content is served directly from cache
- Stale: Content is served from cache while a background refresh is triggered
- Missing: Content is generated synchronously and cached
Performance Considerations
- Uses
fastcgi_finish_request()
when available for non-blocking updates - Implements locking to prevent cache stampede
- Serves stale content rather than blocking on regeneration
Development
Code Style & Quality
This project follows PSR-12 coding standards and uses several tools to maintain code quality:
PHP CodeSniffer
Check coding standards:
Automatically fix coding standards violations:
PHPStan
Run static analysis:
The project uses PHPStan Level 8 (maximum) for strict type checking and analysis.
Testing
Run the test suite:
License
This project is licensed under the GPL v2 license.
All versions of stale-cache with dependencies
ext-json Version *