Skip to content

Commit

Permalink
Remove ResponseCache support
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio Ribeiro committed Sep 12, 2022
1 parent c172ead commit f386d33
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 258 deletions.
36 changes: 0 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ The supported CDN services have these package dependencies that you need to choo
Akamai: [akamai-open/edgegrid-auth](https://github.com/akamai/AkamaiOPEN-edgegrid-php)
CloudFront: [aws/aws-sdk-php](https://github.com/aws/aws-sdk-php)

If you want to add another caching layer on your origin, you can also install this one:

[Response Cache](#laravel-response-cache-integration): [spatie/laravel-responsecache](https://github.com/spatie/laravel-responsecache)

## Usage

Do a full read on the `config/edge-flush.php` there's a lot of configuration items and we tried to document them all.
Expand Down Expand Up @@ -166,38 +162,6 @@ Akamai has a 128 bytes limit for the tag list, so if one page is impacted by lot
edge-cache-tag: app-production-7e0ae085d699003a64e5fa7b75daae3d78ace842
```

## Laravel Response Cache integration

If you have Response Cache installed, this package will automatically store its tags per page and when a model is changed it will not only purge the CDN pages related to this page but also bust the Response Cache internal cache. After, when the warmer passes back to warm those pages, Response Cache should also cache those pages again. This ensures that even if CDN hits your origin from a different not-yet-cached-region, responses will be still be blazing fast.

To allow EdgeFlush to warm pages on Jobs, as ResponseCache only allows cached pages to be warmed if they are requested by a browser, you need to use EdgeCache Profile and Hasher on `config/responsecache.php`:

``` php
return [
...

/*
* The given class will determinate if a request should be cached. The
* default class will cache all successful GET-requests.
*
* You can provide your own class given that it implements the
* CacheProfile interface.
*/

'cache_profile' =>
A17\EdgeFlush\Services\ResponseCache\CacheAllSuccessfulGetRequests::class,

/*
* This class is responsible for generating a hash for a request. This hash
* is used to look up an cached response.
*/

'hasher' => \A17\EdgeFlush\Services\ResponseCache\Hasher::class,

...
];
```

## Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
Expand Down
6 changes: 2 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
"nunomaduro/larastan": "^1.0",
"orchestra/testbench": "^6.19",
"phpunit/phpunit": "^9.3",
"spatie/laravel-ray": "^1.9",
"spatie/laravel-responsecache": "^6.0|^7.1"
"spatie/laravel-ray": "^1.9"
},
"autoload": {
"psr-4": {
Expand All @@ -46,8 +45,7 @@
},
"autoload-dev": {
"psr-4": {
"A17\\EdgeFlush\\Tests\\": "tests",
"Spatie\\ResponseCache\\": "vendor/spatie/laravel-responsecache/src"
"A17\\EdgeFlush\\Tests\\": "tests"
}
},
"scripts": {
Expand Down
4 changes: 1 addition & 3 deletions config/edge-flush.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@
'tags' => A17\EdgeFlush\Services\Tags::class,

'warmer' => A17\EdgeFlush\Services\Warmer::class,

// 'response-cache' => A17\EdgeFlush\Services\ResponseCache\Service::class,
],

/**
Expand Down Expand Up @@ -337,7 +335,7 @@

'cloud_front' => [
'enabled' => env('EDGE_FLUSH_CLOUD_FRONT_ENABLED', true),

'sdk_version' => env(
'EDGE_FLUSH_CLOUD_FRONT_SDK_VERSION',
'2016-01-13',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class RemoveResponsecacheColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('edge_flush_tags', function (Blueprint $table) {
$table->dropColumn('response_cache_hash');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('edge_flush_tags', function (Blueprint $table) {
$table
->string('response_cache_hash')
->nullable()
->index();
});
}
}
3 changes: 0 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ parameters:

reportUnmatchedIgnoredErrors: false

stubFiles:
- stubs/phpstan/larastan-facades.php

ignoreErrors:
- '#Internal.*#'
- '#Cannot access offset .* on array\{scheme.*#'
1 change: 0 additions & 1 deletion src/EdgeFlush.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* @method static \A17\EdgeFlush\Services\CacheControl cacheControl()
* @method static \A17\EdgeFlush\Services\Tags tags()
* @method static \A17\EdgeFlush\Services\Warmer warmer()
* @method static \A17\EdgeFlush\Services\ResponseCache\Service responseCache()
* @method static \Illuminate\Http\Request\Request getRequest()
* @method static bool enabled()
* @method static self instance()
Expand Down
3 changes: 1 addition & 2 deletions src/Models/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
* @property string $model
* @property string $tag
* @property int $url_id
* @property string $response_cache_hash
* @property Url $url
*/
class Tag extends Model
{
protected $table = 'edge_flush_tags';

protected $fillable = ['index', 'model', 'tag', 'url_id', 'response_cache_hash'];
protected $fillable = ['index', 'model', 'tag', 'url_id'];

protected $with = ['url'];

Expand Down
15 changes: 1 addition & 14 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,12 @@ public function configureContainer(): void
app($service),
$app->make(config('edge-flush.classes.cache-control')),
$app->make(config('edge-flush.classes.tags')),
$app->make(config('edge-flush.classes.warmer')),
$this->instantiateResponseCache(),
$app->make(config('edge-flush.classes.warmer'))
);
});

$this->app->singleton('a17.edge-flush.cache-control', function () {
return EdgeFlushFacade::cacheControl();
});
}

function instantiateResponseCache(): BaseService|null
{
if (
blank($class = config('edge-flush.classes.response-cache')) ||
!class_exists($class)
) {
return null;
}

return $this->app->make($class);
}
}
1 change: 0 additions & 1 deletion src/Services/Akamai/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Illuminate\Database\Eloquent\Model;
use Symfony\Component\HttpFoundation\Response;
use Akamai\Open\EdgeGrid\Authentication as AkamaiAuthentication;
use A17\EdgeFlush\Services\ResponseCache\Service as ResponseCache;

class Service extends BaseService implements CDNService
{
Expand Down
13 changes: 1 addition & 12 deletions src/Services/EdgeFlush.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Illuminate\Http\Request;
use A17\EdgeFlush\Contracts\CDNService;
use Symfony\Component\HttpFoundation\Response;
use A17\EdgeFlush\Services\ResponseCache\Service as ResponseCache;

class EdgeFlush extends BaseService
{
Expand All @@ -18,16 +17,13 @@ class EdgeFlush extends BaseService

public Warmer $warmer;

public ResponseCache|null $responseCache;

public Request $request;

public function __construct(
CDNService $cdn,
CacheControl $cacheControl,
Tags $tags,
Warmer $warmer,
BaseService|ResponseCache|null $responseCache = null
Warmer $warmer
) {
$this->cdn = $cdn;

Expand All @@ -37,8 +33,6 @@ public function __construct(

$this->warmer = $warmer;

$this->responseCache = $responseCache;

$this->enabled = config('edge-flush.enabled', false);
}

Expand Down Expand Up @@ -78,11 +72,6 @@ public function warmer(): Warmer
return $this->warmer;
}

public function responseCache(): ResponseCache|null
{
return $this->responseCache;
}

public function setRequest(Request $request): self
{
$this->request = $request;
Expand Down
47 changes: 0 additions & 47 deletions src/Services/ResponseCache/CacheAllSuccessfulGetRequests.php

This file was deleted.

36 changes: 0 additions & 36 deletions src/Services/ResponseCache/Hasher.php

This file was deleted.

74 changes: 0 additions & 74 deletions src/Services/ResponseCache/Service.php

This file was deleted.

Loading

0 comments on commit f386d33

Please sign in to comment.