File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -54,7 +54,9 @@ public function newEloquentBuilder($query)
54
54
55
55
public function scopeDisableCache (EloquentBuilder $ query ) : EloquentBuilder
56
56
{
57
- $ query = $ query ->disableModelCaching ();
57
+ if ($ this ->isCachable ()) {
58
+ $ query = $ query ->disableModelCaching ();
59
+ }
58
60
59
61
return $ query ;
60
62
}
Original file line number Diff line number Diff line change 1
1
<?php namespace GeneaLabs \LaravelModelCaching \Tests \Integration ;
2
2
3
3
use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Author ;
4
+ use GeneaLabs \LaravelModelCaching \Tests \Fixtures \PrefixedAuthor ;
4
5
use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Book ;
5
6
use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Profile ;
6
7
use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Publisher ;
@@ -53,6 +54,23 @@ public function testScopeDisablesCaching()
53
54
$ this ->assertNotEquals ($ authors , $ cachedResults );
54
55
}
55
56
57
+ public function testScopeDisablesCachingWhenCalledOnModel ()
58
+ {
59
+ $ key = sha1 ('genealabs:laravel-model-caching:genealabslaravelmodelcachingtestsfixturesauthor ' );
60
+ $ tags = ['genealabs:laravel-model-caching:genealabslaravelmodelcachingtestsfixturesauthor ' ];
61
+ $ authors = (new PrefixedAuthor )
62
+ ->disableCache ()
63
+ ->where ("name " , "Bruno " )
64
+ ->get ();
65
+
66
+ $ cachedResults = $ this ->cache ()
67
+ ->tags ($ tags )
68
+ ->get ($ key )['value ' ];
69
+
70
+ $ this ->assertNull ($ cachedResults );
71
+ $ this ->assertNotEquals ($ authors , $ cachedResults );
72
+ }
73
+
56
74
public function testAllMethodCachingCanBeDisabledViaConfig ()
57
75
{
58
76
config (['laravel-model-caching.disabled ' => true ]);
You can’t perform that action at this time.
0 commit comments