Stale Cache
Published April 13th, 2025 under Misc
I recently developed a PHP package that brings the powerful stale-while-revalidate caching pattern to WordPress.
StaleCache serves stale content to users while refreshing the cache in the background. This means your users never wait for cache regeneration – they get immediate responses while your system quietly updates content behind the scenes.
The package prevents cache stampedes with a locking mechanism, integrates seamlessly with WordPress transients, and leverages FastCGI finish request for truly non-blocking cache updates when using PHP-FPM.
The syntax is based on the facade system used in Laravel (although it currently implements the static methods directly rather than referencing a separate service like in Laravel).
<?php $result = StaleCache::get( 'my_cache_key', [5, 3600, 60], function() { return getExpensiveData(); } );
Check out the full code and documentation on GitHub: https://github.com/ryanhellyer/stale-cache/