@@ -20,22 +20,22 @@ discard block |
||
| 20 | 20 | $key = $instance->makeCacheKey(); |
| 21 | 21 | |
| 22 | 22 | return $instance->cache($tags) |
| 23 | - ->rememberForever($key, function () use ($columns) { |
|
| 23 | + ->rememberForever($key, function() use ($columns) { |
|
| 24 | 24 | return parent::all($columns); |
| 25 | 25 | }); |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | public static function bootCachable() |
| 29 | 29 | { |
| 30 | - static::created(function ($instance) { |
|
| 30 | + static::created(function($instance) { |
|
| 31 | 31 | $instance->checkCooldownAndFlushAfterPersisting($instance); |
| 32 | 32 | }); |
| 33 | 33 | |
| 34 | - static::deleted(function ($instance) { |
|
| 34 | + static::deleted(function($instance) { |
|
| 35 | 35 | $instance->checkCooldownAndFlushAfterPersisting($instance); |
| 36 | 36 | }); |
| 37 | 37 | |
| 38 | - static::saved(function ($instance) { |
|
| 38 | + static::saved(function($instance) { |
|
| 39 | 39 | $instance->checkCooldownAndFlushAfterPersisting($instance); |
| 40 | 40 | }); |
| 41 | 41 | |
@@ -44,15 +44,15 @@ discard block |
||
| 44 | 44 | // $instance->checkCooldownAndFlushAfterPersisting($instance); |
| 45 | 45 | // }); |
| 46 | 46 | |
| 47 | - static::pivotAttached(function ($instance) { |
|
| 47 | + static::pivotAttached(function($instance) { |
|
| 48 | 48 | $instance->checkCooldownAndFlushAfterPersisting($instance); |
| 49 | 49 | }); |
| 50 | 50 | |
| 51 | - static::pivotDetached(function ($instance) { |
|
| 51 | + static::pivotDetached(function($instance) { |
|
| 52 | 52 | $instance->checkCooldownAndFlushAfterPersisting($instance); |
| 53 | 53 | }); |
| 54 | 54 | |
| 55 | - static::pivotUpdated(function ($instance) { |
|
| 55 | + static::pivotUpdated(function($instance) { |
|
| 56 | 56 | $instance->checkCooldownAndFlushAfterPersisting($instance); |
| 57 | 57 | }); |
| 58 | 58 | } |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | |
| 69 | 69 | public function newEloquentBuilder($query) |
| 70 | 70 | { |
| 71 | - if (! $this->isCachable()) { |
|
| 71 | + if (!$this->isCachable()) { |
|
| 72 | 72 | $this->isCachable = false; |
| 73 | 73 | |
| 74 | 74 | return new EloquentBuilder($query); |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | EloquentBuilder $query, |
| 91 | 91 | int $seconds = null |
| 92 | 92 | ) : EloquentBuilder { |
| 93 | - if (! $seconds) { |
|
| 93 | + if (!$seconds) { |
|
| 94 | 94 | $seconds = $this->cacheCooldownSeconds; |
| 95 | 95 | } |
| 96 | 96 | |
@@ -99,13 +99,13 @@ discard block |
||
| 99 | 99 | $cacheKey = "{$cachePrefix}:{$modelClassName}-cooldown:seconds"; |
| 100 | 100 | |
| 101 | 101 | $this->cache() |
| 102 | - ->rememberForever($cacheKey, function () use ($seconds) { |
|
| 102 | + ->rememberForever($cacheKey, function() use ($seconds) { |
|
| 103 | 103 | return $seconds; |
| 104 | 104 | }); |
| 105 | 105 | |
| 106 | 106 | $cacheKey = "{$cachePrefix}:{$modelClassName}-cooldown:invalidated-at"; |
| 107 | 107 | $this->cache() |
| 108 | - ->rememberForever($cacheKey, function () { |
|
| 108 | + ->rememberForever($cacheKey, function() { |
|
| 109 | 109 | return (new Carbon)->now(); |
| 110 | 110 | }); |
| 111 | 111 | |
@@ -166,24 +166,24 @@ |
||
| 166 | 166 | return $this->cachedValue(func_get_args(), $cacheKey); |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - /** |
|
| 170 | - * Get the relation instance for the given relation name. |
|
| 171 | - * This is overloaded so we can disable model cache on |
|
| 172 | - * relations if parent has disabled model caching. |
|
| 173 | - * |
|
| 174 | - * @param string $name |
|
| 175 | - * @return \Illuminate\Database\Eloquent\Relations\Relation |
|
| 176 | - */ |
|
| 177 | - public function getRelation($name) |
|
| 178 | - { |
|
| 179 | - $relation = parent::getRelation($name); |
|
| 180 | - |
|
| 181 | - if(!$this->isCachable() && is_a($relation->getQuery(), self::class)){ |
|
| 182 | - $relation->getQuery()->disableModelCaching(); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - return $relation; |
|
| 186 | - } |
|
| 169 | + /** |
|
| 170 | + * Get the relation instance for the given relation name. |
|
| 171 | + * This is overloaded so we can disable model cache on |
|
| 172 | + * relations if parent has disabled model caching. |
|
| 173 | + * |
|
| 174 | + * @param string $name |
|
| 175 | + * @return \Illuminate\Database\Eloquent\Relations\Relation |
|
| 176 | + */ |
|
| 177 | + public function getRelation($name) |
|
| 178 | + { |
|
| 179 | + $relation = parent::getRelation($name); |
|
| 180 | + |
|
| 181 | + if(!$this->isCachable() && is_a($relation->getQuery(), self::class)){ |
|
| 182 | + $relation->getQuery()->disableModelCaching(); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + return $relation; |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | 188 | protected function recursiveImplodeWithKey(array $items, string $glue = "_") : string |
| 189 | 189 | { |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | public function avg($column) |
| 17 | 17 | { |
| 18 | - if (! $this->isCachable()) { |
|
| 18 | + if (!$this->isCachable()) { |
|
| 19 | 19 | return parent::avg($column); |
| 20 | 20 | } |
| 21 | 21 | |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | public function count($columns = "*") |
| 28 | 28 | { |
| 29 | - if (! $this->isCachable()) { |
|
| 29 | + if (!$this->isCachable()) { |
|
| 30 | 30 | return parent::count($columns); |
| 31 | 31 | } |
| 32 | 32 | |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | */ |
| 57 | 57 | public function find($id, $columns = ["*"]) |
| 58 | 58 | { |
| 59 | - if (! $this->isCachable()) { |
|
| 59 | + if (!$this->isCachable()) { |
|
| 60 | 60 | return parent::find($id, $columns); |
| 61 | 61 | } |
| 62 | 62 | |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | |
| 73 | 73 | public function first($columns = ["*"]) |
| 74 | 74 | { |
| 75 | - if (! $this->isCachable()) { |
|
| 75 | + if (!$this->isCachable()) { |
|
| 76 | 76 | return parent::first($columns); |
| 77 | 77 | } |
| 78 | 78 | |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | |
| 92 | 92 | public function get($columns = ["*"]) |
| 93 | 93 | { |
| 94 | - if (! $this->isCachable()) { |
|
| 94 | + if (!$this->isCachable()) { |
|
| 95 | 95 | return parent::get($columns); |
| 96 | 96 | } |
| 97 | 97 | |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | public function max($column) |
| 126 | 126 | { |
| 127 | - if (! $this->isCachable()) { |
|
| 127 | + if (!$this->isCachable()) { |
|
| 128 | 128 | return parent::max($column); |
| 129 | 129 | } |
| 130 | 130 | |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | |
| 136 | 136 | public function min($column) |
| 137 | 137 | { |
| 138 | - if (! $this->isCachable()) { |
|
| 138 | + if (!$this->isCachable()) { |
|
| 139 | 139 | return parent::min($column); |
| 140 | 140 | } |
| 141 | 141 | |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | $pageName = "page", |
| 151 | 151 | $page = null |
| 152 | 152 | ) { |
| 153 | - if (! $this->isCachable()) { |
|
| 153 | + if (!$this->isCachable()) { |
|
| 154 | 154 | return parent::paginate($perPage, $columns, $pageName, $page); |
| 155 | 155 | } |
| 156 | 156 | |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | { |
| 179 | 179 | $relation = parent::getRelation($name); |
| 180 | 180 | |
| 181 | - if(!$this->isCachable() && is_a($relation->getQuery(), self::class)){ |
|
| 181 | + if (!$this->isCachable() && is_a($relation->getQuery(), self::class)) { |
|
| 182 | 182 | $relation->getQuery()->disableModelCaching(); |
| 183 | 183 | } |
| 184 | 184 | |
@@ -191,12 +191,12 @@ discard block |
||
| 191 | 191 | |
| 192 | 192 | foreach ($items as $key => $value) { |
| 193 | 193 | if (is_array($value)) { |
| 194 | - $result .= $key . $glue . $this->recursiveImplodeWithKey($value, $glue); |
|
| 194 | + $result .= $key.$glue.$this->recursiveImplodeWithKey($value, $glue); |
|
| 195 | 195 | |
| 196 | 196 | continue; |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | - $result .= $glue . $key . $glue . $value; |
|
| 199 | + $result .= $glue.$key.$glue.$value; |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | return $result; |
@@ -204,11 +204,11 @@ discard block |
||
| 204 | 204 | |
| 205 | 205 | public function pluck($column, $key = null) |
| 206 | 206 | { |
| 207 | - if (! $this->isCachable()) { |
|
| 207 | + if (!$this->isCachable()) { |
|
| 208 | 208 | return parent::pluck($column, $key); |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - $keyDifferentiator = "-pluck_{$column}" . ($key ? "_{$key}" : ""); |
|
| 211 | + $keyDifferentiator = "-pluck_{$column}".($key ? "_{$key}" : ""); |
|
| 212 | 212 | $cacheKey = $this->makeCacheKey([$column], null, $keyDifferentiator); |
| 213 | 213 | |
| 214 | 214 | return $this->cachedValue(func_get_args(), $cacheKey); |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | |
| 217 | 217 | public function sum($column) |
| 218 | 218 | { |
| 219 | - if (! $this->isCachable()) { |
|
| 219 | + if (!$this->isCachable()) { |
|
| 220 | 220 | return parent::sum($column); |
| 221 | 221 | } |
| 222 | 222 | |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | |
| 235 | 235 | public function value($column) |
| 236 | 236 | { |
| 237 | - if (! $this->isCachable()) { |
|
| 237 | + if (!$this->isCachable()) { |
|
| 238 | 238 | return parent::value($column); |
| 239 | 239 | } |
| 240 | 240 | |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | return $this->cache($cacheTags) |
| 304 | 304 | ->rememberForever( |
| 305 | 305 | $hashedCacheKey, |
| 306 | - function () use ($arguments, $cacheKey, $method) { |
|
| 306 | + function() use ($arguments, $cacheKey, $method) { |
|
| 307 | 307 | return [ |
| 308 | 308 | "key" => $cacheKey, |
| 309 | 309 | "value" => parent::{$method}(...$arguments), |