Skip to content

Commit db70b30

Browse files
authored
Merge pull request #38 from GeneaLabs/laravel-5.5
Add functionality to update cache after deleting model
2 parents 0cf6758 + 62998a2 commit db70b30

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"mockery/mockery": "0.9.*",
2020
"phpmd/phpmd": "^2.6",
2121
"phpunit/phpunit": "5.7.*",
22-
"satooshi/php-coveralls" : "dev-master@dev",
22+
"satooshi/php-coveralls" : "*",
2323
"sebastian/phpcpd": "*"
2424
},
2525
"autoload": {

src/CachedBuilder.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ public function cursor()
3131
});
3232
}
3333

34+
public function delete()
35+
{
36+
$this->cache($this->makeCacheTags())
37+
->flush();
38+
39+
return parent::delete();
40+
}
41+
3442
/**
3543
* @SuppressWarnings(PHPMD.ShortVariable)
3644
*/

tests/Unit/CachedBuilderTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,4 +660,27 @@ public function testRawOrderByWithoutColumnReference()
660660
$this->assertTrue($cachedResults->diffAssoc($authors)->isEmpty());
661661
$this->assertTrue($liveResults->diffAssoc($authors)->isEmpty());
662662
}
663+
664+
public function testDelete()
665+
{
666+
$author = (new Author)
667+
->first();
668+
$liveResult = (new UncachedAuthor)
669+
->first();
670+
$authorId = $author->id;
671+
$liveResultId = $liveResult->id;
672+
$key = 'genealabslaravelmodelcachingtestsfixturesauthor';
673+
$tags = ['genealabslaravelmodelcachingtestsfixturesauthor'];
674+
675+
$author->delete();
676+
$liveResult->delete();
677+
$cachedResult = cache()
678+
->tags($tags)
679+
->get($key);
680+
$deletedAuthor = (new Author)->find($authorId);
681+
682+
$this->assertEquals($liveResultId, $authorId);
683+
$this->assertNull($cachedResult);
684+
$this->assertNull($deletedAuthor);
685+
}
663686
}

0 commit comments

Comments
 (0)