megaads/interceptor is a Laravel package for interceptor - route caching engine for laravel.
It currently has 2 GitHub stars and 803 downloads on Packagist (latest version 1.0.30).
Install it with composer require megaads/interceptor.
Discover more Laravel packages by megaads
or browse all Laravel packages to compare alternatives.
Last updated
Interceptor is a powerful route caching module for Laravel, designed to boost application performance by caching full HTTP responses. It handles cache management, automatic garbage collection, and supports device-specific caching.
Install via Composer:
composer require megaads/interceptor
Laravel > 5.5: The package should be auto-discovered.
Laravel < 5.5:
Add the service provider to your config/app.php:
'providers' => [
// ...
Megaads\Interceptor\InterceptorServiceProvider::class,
],
Publish the configuration file to customize the settings:
php artisan vendor:publish --provider="Megaads\Interceptor\InterceptorServiceProvider"
Measurements generally will be available in config/interceptor.php.
The configuration file config/interceptor.php allows you to tweak various aspects:
true to use file storage instead of Redis.cookies: Skip if specific cookies are present.ips: Skip specific IP addresses or ranges (wildcards supported).userAgents: Skip specific User Agents (Regex supported).headers: Skip based on request headers.routes: Skip specific route patterns.Apply the interceptor middleware to the routes or groups you want to cache in your routes/web.php or routes/api.php:
Route::group(['middleware' => 'interceptor'], function () {
Route::get('/', 'HomeController@index');
Route::get('/category/{slug}', 'CategoryController@show');
});
The package provides several Artisan commands for managing the cache:
Flush all cache:
php artisan interceptor:flush
Monitor cache stats:
# Check total cache count
php artisan interceptor:monitor sum
# List cache keys (optional device filter)
php artisan interceptor:monitor list
php artisan interceptor:monitor list mobile
# Check specific URL keys
php artisan interceptor:monitor check "https://example.com/foo"
Remove specific cache:
# Remove cache for a specific URL (all devices)
php artisan interceptor:remove "https://example.com/foo"
Refesh specific cache:
# Refresh cache for a specific URL (all devices)
php artisan interceptor:refresh url "https://example.com/foo"
# Refresh out-of-date cache items (limit 10)
php artisan interceptor:refresh outofdate 10
Manually trigger garbage collection:
php artisan interceptor:garbage
Interceptor adds the following headers to cached responses to help you debug:
Served-From: interceptor (Indicates the response came from this package)Interceptor-Cache-State: HIT or MISSInterceptor-Cache-Time: Timestamp of when the cache was created.Interceptor-Meta-Data: JSON encoded metadata about the cache request.This project is licensed under the MIT License.
Email: [email protected] | [email protected]
If you find a bug, please report it here on Github