Skip to content

Commit c27ce8b

Browse files
committed
Fix cache prefix issue introduced in last update
Fixes #248
1 parent 2d4c35a commit c27ce8b

30 files changed

+245
-263
lines changed

src/CacheKey.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function make(
4343
$key .= $this->getOffsetClause();
4444
$key .= $this->getLimitClause();
4545
$key .= $keyDifferentiator;
46-
46+
// dump($key);
4747
return $key;
4848
}
4949

src/CachedModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
44
use Illuminate\Database\Eloquent\Model;
55

6-
abstract class CachedModel extends Model
6+
class CachedModel extends Model
77
{
88
use Cachable;
99
}

src/Traits/Buildable.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
<?php namespace GeneaLabs\LaravelModelCaching\Traits;
22

3-
use Illuminate\Support\Collection;
4-
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\BaseModel;
5-
63
/**
74
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
85
*/
@@ -291,18 +288,14 @@ protected function retrieveCachedValue(
291288
string $hashedCacheKey,
292289
string $method
293290
) {
294-
$model = new BaseModel;
295-
296291
if (property_exists($this, "model")) {
297-
$model = $this->model;
292+
$this->checkCooldownAndRemoveIfExpired($this->model);
298293
}
299294

300-
if (\method_exists($this, "getModel")) {
301-
$model = $this->getModel();
295+
if (method_exists($this, "getModel")) {
296+
$this->checkCooldownAndRemoveIfExpired($this->getModel());
302297
}
303298

304-
$this->checkCooldownAndRemoveIfExpired($model);
305-
306299
return $this->cache($cacheTags)
307300
->rememberForever(
308301
$hashedCacheKey,

tests/Integration/CachedBuilder/FindOrFailTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ public function testFindOrFailCachesModels()
1111
$author = (new Author)
1212
->findOrFail(1);
1313

14-
$key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-find_1');
14+
$key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-find_1');
1515
$tags = [
16-
'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor',
16+
'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor',
1717
];
1818

1919
$cachedResults = $this->cache()

tests/Integration/CachedBuilder/FindTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ class FindTest extends IntegrationTestCase
99
public function testFindModelResultsCreatesCache()
1010
{
1111
$author = collect()->push((new Author)->find(1));
12-
$key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor_1');
12+
$key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor_1');
1313
$tags = [
14-
'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor',
14+
'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor',
1515
];
1616

1717
$cachedResults = collect()->push($this->cache()->tags($tags)
@@ -26,9 +26,9 @@ public function testFindMultipleModelResultsCreatesCache()
2626
{
2727
$authors = (new Author)
2828
->find([1, 2, 3]);
29-
$key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-find_list_1_2_3');
29+
$key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-find_list_1_2_3');
3030
$tags = [
31-
'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor',
31+
'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor',
3232
];
3333

3434
$cachedResults = $this

tests/Integration/CachedBuilder/ForceDeleteTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ public function testForceDeleteClearsCache()
1414
$resultsBefore = $this
1515
->cache()
1616
->tags([
17-
'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor',
17+
'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor',
1818
])
1919
->get(sha1(
20-
'genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-id_=_1'
20+
'genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-id_=_1'
2121
))["value"];
2222

2323
(new Author)
@@ -26,10 +26,10 @@ public function testForceDeleteClearsCache()
2626
$resultsAfter = $this
2727
->cache()
2828
->tags([
29-
'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor',
29+
'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor',
3030
])
3131
->get(sha1(
32-
'genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-id_=_1'
32+
'genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-id_=_1'
3333
))["value"];
3434

3535
$this->assertEquals(get_class($resultsBefore), get_class($author));

tests/Integration/CachedBuilder/GetTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ public function testGetModelResultsCreatesCache()
1010
{
1111
$authors = (new Author)->with('books', 'profile')
1212
->get();
13-
$key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::profile');
13+
$key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::profile');
1414
$tags = [
15-
'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor',
16-
'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook',
17-
'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesprofile',
15+
'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor',
16+
'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook',
17+
'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesprofile',
1818
];
1919

2020
$cachedResults = $this->cache()->tags($tags)
@@ -45,9 +45,9 @@ public function testAccessingGetResultsViaArrayIndexDoesNotError()
4545

4646
public function testGetWithFieldArrayCachesResults()
4747
{
48-
$key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor_id_name');
48+
$key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor_id_name');
4949
$tags = [
50-
'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor',
50+
'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor',
5151
];
5252

5353
$authors = (new Author)

tests/Integration/CachedBuilder/LazyLoadTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ public function testLazyLoadingRelationshipQuery()
1616
->books
1717
->first()
1818
->id;
19-
$key = sha1("genealabs:laravel-model-caching:testing::memory::test-prefix:book-store:genealabslaravelmodelcachingcachedbelongstomany-book_store.book_id_=_{$bookId}");
19+
$key = sha1("genealabs:laravel-model-caching:testing::memory::book-store:genealabslaravelmodelcachingcachedbelongstomany-book_store.book_id_=_{$bookId}");
2020
$tags = [
21-
'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesstore',
21+
'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesstore',
2222
];
2323

2424
$stores = (new Book)

tests/Integration/CachedBuilder/MorphOneTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ public function setUp() : void
2222

2323
public function testMorphTo()
2424
{
25-
$key1 = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:books:genealabslaravelmodelcachingtestsfixturesbook-author_id_=_1-testing::memory::image');
26-
$key2 = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:books:genealabslaravelmodelcachingtestsfixturesbook-author_id_=_2-testing::memory::image');
25+
$key1 = sha1('genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook-author_id_=_1-testing::memory::image');
26+
$key2 = sha1('genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook-author_id_=_2-testing::memory::image');
2727
$tags = [
28-
"genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook",
29-
"genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesimage",
28+
"genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook",
29+
"genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesimage",
3030
];
3131

3232
$books1 = (new Book)

tests/Integration/CachedBuilder/PaginateTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ public function testPaginationIsCached()
1616
$authors = (new Author)
1717
->paginate(3);
1818

19-
$key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-paginate_by_3_page_1');
19+
$key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-paginate_by_3_page_1');
2020
$tags = [
21-
'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor',
21+
'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor',
2222
];
2323

2424
$cachedResults = $this
@@ -149,9 +149,9 @@ public function testPaginationWithCustomOptionsReturnsCorrectLinks()
149149

150150
public function testCustomPageNamePagination()
151151
{
152-
$key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-paginate_by_3_custom-page_1');
152+
$key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-paginate_by_3_custom-page_1');
153153
$tags = [
154-
'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor',
154+
'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor',
155155
];
156156

157157
$authors = (new Author)

0 commit comments

Comments
 (0)