11<?php namespace GeneaLabs \LaravelModelCaching \Traits ;
22
3- use Carbon \Carbon ;
43use Closure ;
54use GeneaLabs \LaravelModelCaching \CachedBuilder ;
65use GeneaLabs \LaravelModelCaching \CacheKey ;
76use GeneaLabs \LaravelModelCaching \CacheTags ;
87use Illuminate \Cache \TaggableStore ;
8+ use Illuminate \Container \Container ;
99use Illuminate \Database \Eloquent \Model ;
1010use Illuminate \Database \Eloquent \Scope ;
1111use Illuminate \Database \Query \Builder ;
12+ use Illuminate \Support \Carbon ;
1213
1314trait Caching
1415{
@@ -62,10 +63,14 @@ protected function applyScopesToInstance()
6263
6364 public function cache (array $ tags = [])
6465 {
65- $ cache = app ('cache ' );
66-
67- if (config ('laravel-model-caching.store ' )) {
68- $ cache = $ cache ->store (config ('laravel-model-caching.store ' ));
66+ $ cache = Container::getInstance ()
67+ ->make ("cache " );
68+ $ config = Container::getInstance ()
69+ ->make ("config " )
70+ ->get ("laravel-model-caching.store " );
71+
72+ if ($ config ) {
73+ $ cache = $ cache ->store ($ config );
6974 }
7075
7176 if (is_subclass_of ($ cache ->getStore (), TaggableStore::class)) {
@@ -106,7 +111,9 @@ public function flushCache(array $tags = [])
106111
107112 protected function getCachePrefix () : string
108113 {
109- $ cachePrefix = config ("laravel-model-caching.cache-prefix " , "" );
114+ $ cachePrefix = Container::getInstance ()
115+ ->make ("config " )
116+ ->get ("laravel-model-caching.cache-prefix " , "" );
110117
111118 if ($ this ->model
112119 && property_exists ($ this ->model , "cachePrefix " )
@@ -140,7 +147,9 @@ protected function makeCacheKey(
140147 }
141148
142149 $ query = $ this ->query
143- ?? app ('db ' )->query ();
150+ ?? Container::getInstance ()
151+ ->make ("db " )
152+ ->query ();
144153
145154 if ($ this ->query
146155 && method_exists ($ this ->query , "getQuery " )
@@ -160,7 +169,9 @@ protected function makeCacheTags() : array
160169 : $ this ;
161170 $ query = $ this ->query instanceof Builder
162171 ? $ this ->query
163- : app ('db ' )->query ();
172+ : Container::getInstance ()
173+ ->make ("db " )
174+ ->query ();
164175 $ tags = (new CacheTags ($ eagerLoad , $ model , $ query ))
165176 ->make ();
166177
@@ -259,8 +270,12 @@ protected function checkCooldownAndFlushAfterPersisting(Model $instance, string
259270
260271 public function isCachable () : bool
261272 {
273+ $ isCacheDisabled = Container::getInstance ()
274+ ->make ("config " )
275+ ->get ("laravel-model-caching.disabled " );
276+
262277 return $ this ->isCachable
263- && ! config ( ' laravel-model-caching.disabled ' ) ;
278+ && ! $ isCacheDisabled ;
264279 }
265280
266281 protected function setCacheCooldownSavedAtTimestamp (Model $ instance )
0 commit comments