erashdan/laravelfastly

A Laravel wrapper for Fastly SDK


Keywords
php, laravel, fastly
License
MIT

Documentation

Fastly Laravel Build Status

This is a wrapper around Fastly SDK for Laravel.

Installation

This package can be used in Laravel 5.5 or higher.

You can install the package via composer:

composer require erashdan/laravelfastly

Laravel's package auto discovery will automatically register the service provider for you.

Then you need to publish the configuration to your project:

php artisan vendor:publish --provider="Erashdan\LaravelFastly\FastlyServiceProvider" --tag="config"

And add the key used for the hashing in .env file

FASTLY_API_KEY=GENERATE_KEY_FROM_FASTLY_ACCOUNT

Usage

You can clear the cache from fastly using the Fastly Facade

Purge by URL

Fastly::purgeUrl('get-url')

The facade also accept an array of URIs to be cleared

Fastly::purgeUrl(['first-url', 'second-url'])

Purge by service id

First you should define services array in configuration fastly.php

'services' => [
    'main' => 'xDp52XsJ5dXLp',
]

You can call fastly Facades to purge all files by service name.

Fastly::purgeService('main');

Call method

You can request fastly service to cache a specific url by using call method

Fastly::callUrl('https://erashdan.com');

Purge and call

You can purge specific url and re-cache (call) it by using purgeAndCall method

Fastly::purgeAndCall('https://erashdan.com');

Testing

composer test

Credits

TODO

- [x] Build first version.
- [x] Purge by service ID
- [x] Call fastly `call` wrapper.
- [] Implement `call` using URI