File tree Expand file tree Collapse file tree 3 files changed +45
-1
lines changed Expand file tree Collapse file tree 3 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
4
4
The format is based on [ Keep a Changelog] ( http://keepachangelog.com/en/1.0.0/ )
5
5
and this project adheres to [ Semantic Versioning] ( http://semver.org/spec/v2.0.0.html ) .
6
6
7
+ ## [ 0.2.50] - 10 Mar 2018
8
+ ### Added
9
+ - cache invalidation when ` destroy() ` ing models.
10
+
11
+ ### Fixed
12
+ - cache tag generation when calling ` all() ` queries that prevented proper
13
+ cache invalidation.
14
+
7
15
## [ 0.2.49] - 9 Mar 2018
8
16
### Fixed
9
17
- caching of ` ->first() ` queries.
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ public static function all($columns = ['*'])
13
13
14
14
$ class = get_called_class ();
15
15
$ instance = new $ class ;
16
- $ tags = [ str_slug ( get_called_class ())] ;
16
+ $ tags = $ instance -> makeCacheTags () ;
17
17
$ key = $ instance ->makeCacheKey ();
18
18
19
19
return $ instance ->cache ($ tags )
@@ -24,6 +24,9 @@ public static function all($columns = ['*'])
24
24
25
25
public static function bootCachable ()
26
26
{
27
+ static ::deleted (function ($ instance ) {
28
+ $ instance ->checkCooldownAndFlushAfterPersiting ($ instance );
29
+ });
27
30
static ::saved (function ($ instance ) {
28
31
$ instance ->checkCooldownAndFlushAfterPersiting ($ instance );
29
32
});
@@ -41,6 +44,15 @@ public static function bootCachable()
41
44
});
42
45
}
43
46
47
+ public static function destroy ($ ids )
48
+ {
49
+ $ class = get_called_class ();
50
+ $ instance = new $ class ;
51
+ $ instance ->flushCache ();
52
+
53
+ return parent ::destroy ($ ids );
54
+ }
55
+
44
56
public function newEloquentBuilder ($ query )
45
57
{
46
58
if (! $ this ->isCachable ()) {
Original file line number Diff line number Diff line change @@ -38,4 +38,28 @@ public function testCallingGetThenFirstQueriesReturnsDifferingResults()
38
38
$ this ->assertInstanceOf (Author::class, $ firstAuthor );
39
39
$ this ->assertInstanceOf (Collection::class, $ allAuthors );
40
40
}
41
+
42
+ public function testUsingDestroyInvalidatesCache ()
43
+ {
44
+ $ allAuthors = (new Author )->get ();
45
+ $ firstAuthor = $ allAuthors ->first ();
46
+ (new Author )->destroy ($ firstAuthor ->id );
47
+ $ updatedAuthors = (new Author )->get ()->keyBy ("id " );
48
+
49
+ $ this ->assertNotEquals ($ allAuthors , $ updatedAuthors );
50
+ $ this ->assertTrue ($ allAuthors ->contains ($ firstAuthor ));
51
+ $ this ->assertFalse ($ updatedAuthors ->contains ($ firstAuthor ));
52
+ }
53
+
54
+ public function testAllMethodCacheGetsInvalidated ()
55
+ {
56
+ $ allAuthors = (new Author )->all ();
57
+ $ firstAuthor = $ allAuthors ->first ();
58
+ $ firstAuthor ->delete ();
59
+ $ updatedAuthors = (new Author )->all ();
60
+
61
+ $ this ->assertNotEquals ($ allAuthors , $ updatedAuthors );
62
+ $ this ->assertTrue ($ allAuthors ->contains ($ firstAuthor ));
63
+ $ this ->assertFalse ($ updatedAuthors ->contains ($ firstAuthor ));
64
+ }
41
65
}
You can’t perform that action at this time.
0 commit comments