PHP code example of 7lab / laravel-responsecache

1. Go to this page and download the library: Download 7lab/laravel-responsecache library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

7lab / laravel-responsecache example snippets


return [

    /*
     * Determine if the response cache middleware should be enabled.
     */
    'enabled' => env('RESPONSECACHE_ENABLED', true),

    /*
     * Specify the tag name that will be used for the cache.
     */
    'tag' => env('RESPONSECACHE_TAG', 'responsecache'),

];

...

protected $routeMiddleware = [
    ...
    'cacheResponse' => \SevenLab\ResponseCache\Middleware\CacheResponse::class,
    'doNotCacheResponse' => \SevenLab\ResponseCache\Middleware\DoNotCacheResponse::class,
];

...

// cache this route for 5 minutes
Route::get('/my-special-snowflake', 'SnowflakeController@index')->middleware('cacheResponse:5');

// cache all these routes for 10 minutes
Route::group(function() {
   Route::get('/another-special-snowflake', 'AnotherSnowflakeController@index');
   
   Route::get('/yet-another-special-snowflake', 'YetAnotherSnowflakeController@index');
})->middleware('cacheResponse:10');

Route::get('/auth/logout', 'AuthController@getLogout')->name('auth.logout')->middleware('doNotCacheResponse');

class AuthController extends Controller
{
    public function __construct()
    {
        $this->middleware('doNotCacheResponse', ['only' => ['getLogout']]);
    }
}

ResponseCache::forget(['auth.logout']);

ResponseCache::clear();
bash
php artisan vendor:publish --provider="SevenLab\ResponseCache\ResponseCacheServiceProvider"
bash
php artisan responsecache:forget auth.logout
bash
php artisan responsecache:clear