PHPackages                             darkperis/dpfastly-laravel - 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. darkperis/dpfastly-laravel

ActiveLibrary[Caching](/categories/caching)

darkperis/dpfastly-laravel
==========================

Fastly Cache Implementation for Laravel

v1.0.2(9mo ago)030GPL-3.0-onlyPHP

Since Apr 3Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/darkperis/dpfastly-laravel)[ Packagist](https://packagist.org/packages/darkperis/dpfastly-laravel)[ RSS](/packages/darkperis-dpfastly-laravel/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (4)Used By (0)

Laravel Fastly
--------------

[](#laravel-fastly)

This package allows you to use Fastly together with Laravel.

It provides one facade:

- Fastly facade to handle purging

Installation
------------

[](#installation)

Require this package using composer.

```
composer require darkperis/dpfastly-laravel

```

Laravel uses Auto-Discovery, so you won't have to make any changes to your application, the two middlewares and facade will be available right from the beginning.

#### Steps for Laravel &gt;=5.1 and &lt;=5.4

[](#steps-for-laravel-51-and-54)

The package can be used for Laravel 5.1 to 5.4 as well, however due to lack of Auto-Discovery, a few additional steps have to be performed.

In `config/app.php` you have to add the following code in your `aliases`:

```
'aliases' => [
    ...
    'Fastly'   => Darkpony\Fastly\Fastly::class,
],

```

Copy `fastly.php` to `config/`:

Copy the package `config/fastly.php` file to your `config/` directory.

**important**: Do not add the ServiceProvider under `providers` in `config/app.php`.

#### Steps for Laravel 5.5 and above

[](#steps-for-laravel-55-and-above)

You should publish the package configuration, which allows you to set the defaults for the `Cache-Control` header:

```
php artisan vendor:publish --provider="Darkpony\Fastly\FastlyServiceProvider"

```

Usage
-----

[](#usage)

The package comes with 2 functionalities: Setting the cache control headers for Fastly and purging.

### cache-control

[](#cache-control)

You'll be able to configure defaults in the `config/fastly.php` file, here you can set the max-age (`default_ttl`), the cacheability (`default_cacheability`) such as public, private or no-cache or enable esi (`esi`) in the `Cache-Control` response header.

If the `default_ttl` is set to `0`, then we won't return the `Cache-Control` response header.

You can control the config settings in your `.env` file as such:

- `FASTLY_API_KEY` - Specify the API Token for your Service at the Edgeport Platform
- `FASTLY_ENDPOINT` - accepts endpoint
- `FASTLY_ESI_ENABLED` - accepts `true` or `false` to whether you want ESI enabled or not globally; Default `false`
- `FASTLY_DEFAULT_TTL` - accepts an integer, this value is in seconds; Default: `0`
- `FASTLY_DEFAULT_CACHEABILITY` - accepts a string, you can use values such as `private`, `no-cache`, `public` or `no-vary`; Default: `no-cache`
- `FASTLY_GUEST_ONLY` - accepts `true` or `false` to decide if the cache should be enabled for guests only; Defaults to `false`

You set the cache-control header for fastly using a middleware, so we can in our routes do something like this:

```
Route::get('/', function() {
    return view('frontpage');
})->middleware('cache.headers:public;max_age=2628000;etag');
```

### purge

[](#purge)

If we have an admin interface that controls for example a blog, when you publish a new article, you might want to purge the frontpage of the blog so the article appears in the overview.

You'd do this in your controller by doing

```
