File tree Expand file tree Collapse file tree 3 files changed +33
-4
lines changed Expand file tree Collapse file tree 3 files changed +33
-4
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ public function cache(array $tags = [])
25
25
return $ cache ;
26
26
}
27
27
28
- public function disableCache ()
28
+ public function disableModelCaching ()
29
29
{
30
30
$ this ->isCachable = false ;
31
31
Original file line number Diff line number Diff line change @@ -52,6 +52,13 @@ public function newEloquentBuilder($query)
52
52
return new CachedBuilder ($ query );
53
53
}
54
54
55
+ public function scopeDisableCache (EloquentBuilder $ query ) : EloquentBuilder
56
+ {
57
+ $ query = $ query ->disableModelCaching ();
58
+
59
+ return $ query ;
60
+ }
61
+
55
62
public function scopeWithCacheCooldownSeconds (
56
63
EloquentBuilder $ query ,
57
64
int $ seconds
Original file line number Diff line number Diff line change @@ -17,21 +17,43 @@ class DisabledCachedModelTest extends IntegrationTestCase
17
17
{
18
18
use RefreshDatabase;
19
19
20
- public function testAllModelResultsIsNotCached ()
20
+ public function testCacheCanBeDisabledOnModel ()
21
21
{
22
22
$ key = sha1 ('genealabslaravelmodelcachingtestsfixturesauthor ' );
23
23
$ tags = ['genealabslaravelmodelcachingtestsfixturesauthor ' ];
24
24
$ authors = (new Author )
25
25
->disableCache ()
26
- ->all ();
26
+ ->get ();
27
27
28
28
$ cachedResults = $ this ->cache ()
29
29
->tags ($ tags )
30
30
->get ($ key );
31
31
$ liveResults = (new UncachedAuthor )
32
- ->all ();
32
+ ->get ();
33
33
34
34
$ this ->assertEmpty ($ liveResults ->diffAssoc ($ authors ));
35
35
$ this ->assertNull ($ cachedResults );
36
36
}
37
+
38
+ public function testCacheCanBeDisabledOnQuery ()
39
+ {
40
+ $ key = sha1 ('genealabslaravelmodelcachingtestsfixturesauthor ' );
41
+ $ tags = ['genealabslaravelmodelcachingtestsfixturesauthor ' ];
42
+ $ authors = (new Author )
43
+ ->with ('books ' )
44
+ ->disableCache ()
45
+ ->get ()
46
+ ->keyBy ("id " );
47
+
48
+ $ cachedResults = $ this ->cache ()
49
+ ->tags ($ tags )
50
+ ->get ($ key );
51
+ $ liveResults = (new UncachedAuthor )
52
+ ->with ('books ' )
53
+ ->get ()
54
+ ->keyBy ("id " );
55
+
56
+ $ this ->assertNull ($ cachedResults );
57
+ $ this ->assertEmpty ($ liveResults ->diffKeys ($ authors ));
58
+ }
37
59
}
You can’t perform that action at this time.
0 commit comments