PHP code example of barryvdh / laravel-httpcache

1. Go to this page and download the library: Download barryvdh/laravel-httpcache 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/ */

    

barryvdh / laravel-httpcache example snippets


Route::get('my-page', function(){
   return Response::make('Hello!')->setTtl(60); // Cache 1 minute
});

protected $routeMiddleware = [
    // ...
    'ttl' => \Barryvdh\HttpCache\Middleware\SetTtl::class,
];

Route::get('my-page', function(){
   return 'Hello' 
})->middleware('ttl:60'); // Cache 1 minute

App::make('http_cache.store')->purge($url);
\File::cleanDirectory(app('http_cache.cache_dir'));

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

$kernel = \Barryvdh\HttpCache\CacheKernel::wrap($kernel);

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

$response->send();

$kernel->terminate($request, $response);