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)
5454
5555 public function scopeDisableCache (EloquentBuilder $ query ) : EloquentBuilder
5656 {
57- $ query = $ query ->disableModelCaching ();
57+ if ($ this ->isCachable ()) {
58+ $ query = $ query ->disableModelCaching ();
59+ }
5860
5961 return $ query ;
6062 }
Original file line number Diff line number Diff line change 11<?php namespace GeneaLabs \LaravelModelCaching \Tests \Integration ;
22
33use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Author ;
4+ use GeneaLabs \LaravelModelCaching \Tests \Fixtures \PrefixedAuthor ;
45use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Book ;
56use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Profile ;
67use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Publisher ;
@@ -53,6 +54,23 @@ public function testScopeDisablesCaching()
5354 $ this ->assertNotEquals ($ authors , $ cachedResults );
5455 }
5556
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+
5674 public function testAllMethodCachingCanBeDisabledViaConfig ()
5775 {
5876 config (['laravel-model-caching.disabled ' => true ]);
You can’t perform that action at this time.
0 commit comments