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)

tests/Integration/CachedBuilder/ScopeTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public function testScopeClauseParsing()
1515
$authors = (new Author)
1616
->startsWithA()
1717
->get();
18-
$key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-name_like_A%');
19-
$tags = ['genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor'];
18+
$key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-name_like_A%');
19+
$tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor'];
2020

2121
$cachedResults = $this->cache()
2222
->tags($tags)
@@ -38,8 +38,8 @@ public function testScopeClauseWithParameter()
3838
$authors = (new Author)
3939
->nameStartsWith("B")
4040
->get();
41-
$key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-name_like_B%');
42-
$tags = ['genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor'];
41+
$key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-name_like_B%');
42+
$tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor'];
4343

4444
$cachedResults = $this->cache()
4545
->tags($tags)
@@ -60,8 +60,8 @@ public function testGlobalScopesAreCached()
6060
->first();
6161
$authors = (new AuthorBeginsWithA)
6262
->get();
63-
$key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthorbeginswitha');
64-
$tags = ['genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthorbeginswitha'];
63+
$key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthorbeginswitha');
64+
$tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthorbeginswitha'];
6565

6666
$cachedResults = $this->cache()
6767
->tags($tags)

tests/Integration/CachedBuilder/SelectTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ class SelectTest extends IntegrationTestCase
77
{
88
public function testSelectWithRawColumns()
99
{
10-
$key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:books:genealabslaravelmodelcachingtestsfixturesbook_author_id_AVG(id) AS averageIds_orderBy_author_id_asc');
10+
$key = sha1('genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook_author_id_AVG(id) AS averageIds_orderBy_author_id_asc');
1111
$tags = [
12-
'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook',
12+
'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook',
1313
];
1414
$selectArray = [
1515
app("db")->raw("author_id"),
@@ -40,9 +40,9 @@ public function testSelectWithRawColumns()
4040

4141
// public function testSelectFieldsAreCached()
4242
// {
43-
// $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor_id_name-first');
43+
// $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor_id_name-first');
4444
// $tags = [
45-
// 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor',
45+
// 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor',
4646
// ];
4747

4848
// $authorFields = (new Author)

tests/Integration/CachedBuilder/SoftDeletesTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ class SoftDeletesTest extends IntegrationTestCase
88
{
99
public function testWithTrashedIsCached()
1010
{
11-
$key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-authors.id_=_1-first');
11+
$key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-authors.id_=_1-first');
1212
$tags = [
13-
'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor',
13+
'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor',
1414
];
1515
$author = (new UncachedAuthor)
1616
->first();
@@ -33,9 +33,9 @@ public function testWithTrashedIsCached()
3333

3434
// public function testWithoutTrashedIsCached()
3535
// {
36-
// $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor_1-first');
36+
// $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor_1-first');
3737
// $tags = [
38-
// 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor',
38+
// 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor',
3939
// ];
4040
// $author = (new UncachedAuthor)
4141
// ->first();

tests/Integration/CachedBuilder/WhenTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ class WhenTest extends IntegrationTestCase
88
{
99
public function testWhenQuery()
1010
{
11-
$key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:books:genealabslaravelmodelcachingtestsfixturesbook-id_<_5');
11+
$key = sha1('genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook-id_<_5');
1212
$tags = [
13-
'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook',
13+
'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook',
1414
];
1515

1616
$books = (new Book)

tests/Integration/CachedBuilder/WhereInRawTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ class WhereInRawTest extends IntegrationTestCase
88
{
99
public function testWhereInRawUsingRelationship()
1010
{
11-
$key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books');
11+
$key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books');
1212
$tags = [
13-
'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor',
14-
'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook',
13+
'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor',
14+
'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook',
1515
];
1616

1717
$authors = (new Author)

0 commit comments

Comments
 (0)