PHPackages                             shawnley/laravel-httpcache - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. shawnley/laravel-httpcache

ActiveLibrary[Caching](/categories/caching)

shawnley/laravel-httpcache
==========================

HttpCache for Laravel 5

0.2.5(10y ago)0741MITPHPPHP &gt;=5.4.0

Since Feb 6Pushed 10y ago1 watchersCompare

[ Source](https://github.com/Shawnley/laravel-httpcache)[ Packagist](https://packagist.org/packages/shawnley/laravel-httpcache)[ RSS](/packages/shawnley-laravel-httpcache/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (4)Versions (10)Used By (0)

HttpCache for Laravel 5
-----------------------

[](#httpcache-for-laravel-5)

### For Laravel 4.1+, require [v0.1.x](https://github.com/barryvdh/laravel-httpcache/tree/v0.1.1)

[](#for-laravel-41-require-v01x)

Laravel 5 can use [HttpKernelInterface Middlewares](http://stackphp.com/middlewares/), so also [HttpCache](http://symfony.com/doc/current/book/http_cache.html). This package provides a simple ServiceProvider to get you started with HttpCache.

First, require this package in composer.json and run `composer update`

```
"barryvdh/laravel-httpcache": "0.2.x@dev"

```

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

```
'Barryvdh\HttpCache\ServiceProvider',

```

You can now add the Middleware to your Kernel:

```
'Barryvdh\HttpCache\Middleware\CacheRequests',

```

Caching is now enabled, for public responses. Just set the Ttl or MaxSharedAge

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

You can also define a filter.

```
Route::filter('cache', function($route, $request, $response, $age=60){
    $response->setTtl($age);
});
Route::get('cached', array('after' => 'cache:30', function(){
    return 'I am cached 30 seconds!';
}));
```

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

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

```

### ESI

[](#esi)

Enable ESI in your config file and add the Esi Middleware to your Kernel:

```
'Barryvdh\HttpCache\Middleware\ParseEsi',

```

You can now define ESI includes in your layouts.

```
