PHP code example of infusionweb / laravel-middleware-response-cache

1. Go to this page and download the library: Download infusionweb/laravel-middleware-response-cache 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/ */

    

infusionweb / laravel-middleware-response-cache example snippets


// within config/app.php

'providers' => [
    //
    InfusionWeb\Laravel\Http\Middleware\ResponseCacheServiceProvider::class,
];

// within app/Http/Kernel.php

protected $routeMiddleware = [
    //
    'cachebefore' => \InfusionWeb\Laravel\Http\Middleware\ResponseCacheBeforeMiddleware::class,
    'cacheafter' => \InfusionWeb\Laravel\Http\Middleware\ResponseCacheAfterMiddleware::class,
    //
];

// within app/Http/routes.php

Route::get('gallery', ['middleware' => ['cachebefore', 'cacheafter'], function () {
    return 'pictures!';
}]);

// within app/Http/Controllers/GalleryController.php

public function __construct()
{
    $this->middleware(['cachebefore', 'cacheafter']);
}

// within app/Http/Kernel.php

protected $middlewareGroups = [
    'web' => [
        //
        'cachebefore' => \InfusionWeb\Laravel\Http\Middleware\ResponseCacheBeforeMiddleware::class,
        'cacheafter' => \InfusionWeb\Laravel\Http\Middleware\ResponseCacheAfterMiddleware::class,
        //
    ],
    //
];

// within app/Http/routes.php

Route::group(['middleware' => ['web']], function () {
    Route::get('gallery', function () {
        return 'pictures!';
    });
});

return [
    'enable' => env('RESPONSE_CACHE_ENABLE', false),

    // Length of time to cache the HTML response, in minutes.
    'length' => env('RESPONSE_CACHE_LENGTH', 60),
];
bash
$ php artisan vendor:publish --provider="InfusionWeb\Laravel\Http\Middleware\ResponseCacheServiceProvider"