Skip to content

Commit

Permalink
This adds a new cache key to add the current baseURL to the list of k…
Browse files Browse the repository at this point in the history
…eys. This prevents pagination links from being incorrectly cached on a website which has multiple domains.
  • Loading branch information
Drewdan committed Jul 27, 2021
1 parent b8ffa34 commit 829be8a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/CacheKey.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace GeneaLabs\LaravelModelCaching;

use Exception;
use Illuminate\Support\Facades\URL;
use GeneaLabs\LaravelModelCaching\Traits\CachePrefixing;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
Expand Down Expand Up @@ -45,6 +46,7 @@ public function make(
$key .= $this->getOffsetClause();
$key .= $this->getLimitClause();
$key .= $this->getBindingsSlug();
$key .= $this->getPathSlug();
$key .= $keyDifferentiator;
$key .= $this->macroKey;
// dump($key);
Expand Down Expand Up @@ -362,4 +364,9 @@ protected function getBindingsSlug() : string

return Arr::query($this->model->query()->getBindings());
}

protected function getPathSlug() : string
{
return URL::to('/');
}
}
17 changes: 17 additions & 0 deletions tests/Feature/PaginationTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Feature;

use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Artisan;
use GeneaLabs\LaravelModelCaching\Tests\FeatureTestCase;
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Book;

Expand Down Expand Up @@ -82,4 +86,17 @@ public function testCustomPagination()

$response->see($page2ActiveLink);
}

public function testPaginationUrlIsCorrect() {
$this->baseUrl = 'https://test.local';

$this->visit("pagination-test2?custom-page=2")
->see('https://test.local/pagination-test2?custom-page=1');

$this->baseUrl = 'https://changed.local';

$this->visit("pagination-test2?custom-page=2")
->see('https://changed.local/pagination-test2?custom-page=1');

}
}

0 comments on commit 829be8a

Please sign in to comment.