2017 © Pedro Peláez
 

library laravel-httpcache

HttpCache for Laravel 5

image

barryvdh/laravel-httpcache

HttpCache for Laravel 5

  • Monday, May 14, 2018
  • by Barryvdh
  • Repository
  • 17 Watchers
  • 333 Stars
  • 98,090 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 24 Forks
  • 21 Open issues
  • 15 Versions
  • 6 % Grown

The README.md

HttpCache for Laravel

Tests Packagist License Latest Stable Version Total Downloads Fruitcake, (*1)

Laravel can use HttpKernelInterface Middlewares, so also HttpCache. This package provides a simple ServiceProvider to get you started with HttpCache., (*2)

First, require this package with composer, (*3)

composer require barryvdh/laravel-httpcache

After updating, add the ServiceProvider to the array of providers in app/config/app.php, (*4)

'Barryvdh\HttpCache\ServiceProvider',

You can now add the Middleware to your Kernel:, (*5)

'Barryvdh\HttpCache\Middleware\CacheRequests',

Caching is now enabled, for public responses. Just set the Ttl or MaxSharedAge, (*6)

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

You can use the provided SetTtl middleware in your Kernel to simplify this:, (*7)

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

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

Publish the config to change some options (cache dir, default ttl, etc) or enable ESI., (*8)

$ php artisan vendor:publish --provider="Barryvdh\HttpCache\ServiceProvider"

Direct approach, without ServiceProvider

Note: This is still in beta, test with caution. It should be faster, but less flexible because it starts earlier., (*9)

You can also wrap the Kernel in the HttpCache, in your public/index.php. Replace the 'Run The Application' part like this:, (*10)

$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);

ESI

Enable ESI in your config file and add the Esi Middleware to your Kernel:, (*11)

'Barryvdh\HttpCache\Middleware\ParseEsi',

You can now define ESI includes in your layouts., (*12)

<esi:include src="<?= url('partial/page') ?>"/>

This will render partial/page, with it's own TTL. The rest of the page will remain cached (using it's own TTL), (*13)

Purging/flushing the cache

You can purge a single url or just delete the entire cache directory:, (*14)

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

Or use the Artisan httpcache:clear command, (*15)

$ php artisan httpcache:clear

More information

For more information, read the Docs on Symfony HttpCache, (*16)

The Versions

14/05 2018

dev-master

9999999-dev

HttpCache for Laravel 5

  Sources   Download

MIT

The Requires

 

laravel cache esi httpcache

05/03 2018
03/02 2016
09/07 2015

v0.2.3

0.2.3.0

HttpCache for Laravel 5

  Sources   Download

MIT

The Requires

 

laravel cache esi httpcache

02/06 2015

v0.2.1

0.2.1.0

HttpCache for Laravel 5

  Sources   Download

MIT

The Requires

 

laravel cache esi httpcache

02/06 2015

v0.2.2

0.2.2.0

HttpCache for Laravel 5

  Sources   Download

MIT

The Requires

 

laravel cache esi httpcache

18/02 2015

v0.2.0

0.2.0.0

HttpCache for Laravel 5

  Sources   Download

MIT

The Requires

 

laravel cache esi httpcache

27/04 2014

v0.1.1

0.1.1.0

HttpCache for Laravel 4.1

  Sources   Download

MIT

The Requires

 

laravel cache esi httpcache

06/02 2014

v0.1

0.1.0.0

HttpCache for Laravel 4.1

  Sources   Download

MIT

The Requires

 

laravel cache esi httpcache