diff --git a/src/FlushQueryCacheObserver.php b/src/FlushQueryCacheObserver.php index 00b223b..ba049ff 100644 --- a/src/FlushQueryCacheObserver.php +++ b/src/FlushQueryCacheObserver.php @@ -147,6 +147,7 @@ public function morphToManyUpdatedExistingPivot($relation, Model $model, $ids) * @param string|null $relation * @param \Illuminate\Database\Eloquent\Collection|null $pivotedModels * @return void + * * @throws Exception */ protected function invalidateCache(Model $model, $relation = null, $pivotedModels = null): void diff --git a/src/Traits/QueryCacheable.php b/src/Traits/QueryCacheable.php index eaab077..fb0ced2 100644 --- a/src/Traits/QueryCacheable.php +++ b/src/Traits/QueryCacheable.php @@ -91,22 +91,42 @@ protected function newBaseQueryBuilder() $builder->cacheFor($this->cacheFor); } + if (method_exists($this, 'cacheForValue')) { + $builder->cacheFor($this->cacheForValue($builder)); + } + if ($this->cacheTags) { $builder->cacheTags($this->cacheTags); } + if (method_exists($this, 'cacheTagsValue')) { + $builder->cacheTags($this->cacheTagsValue($builder)); + } + if ($this->cachePrefix) { $builder->cachePrefix($this->cachePrefix); } + if (method_exists($this, 'cachePrefixValue')) { + $builder->cachePrefix($this->cachePrefixValue($builder)); + } + if ($this->cacheDriver) { $builder->cacheDriver($this->cacheDriver); } + if (method_exists($this, 'cacheDriverValue')) { + $builder->cacheDriver($this->cacheDriverValue($builder)); + } + if ($this->cacheUsePlainKey) { $builder->withPlainKey(); } + if (method_exists($this, 'cacheUsePlainKeyValue')) { + $builder->withPlainKey($this->cacheUsePlainKeyValue($builder)); + } + return $builder->cacheBaseTags($this->getCacheBaseTags()); } } diff --git a/tests/Models/Book.php b/tests/Models/Book.php index 3b923f2..7cef648 100644 --- a/tests/Models/Book.php +++ b/tests/Models/Book.php @@ -14,4 +14,14 @@ class Book extends Model protected $fillable = [ 'name', ]; + + protected function cacheUsePlainKeyValue() + { + return $this->cacheUsePlainKey; + } + + protected function cacheForValue() + { + return 3600; + } } diff --git a/tests/Models/Kid.php b/tests/Models/Kid.php index a5c23c8..cbe039c 100644 --- a/tests/Models/Kid.php +++ b/tests/Models/Kid.php @@ -21,4 +21,14 @@ protected function getCacheBaseTags(): array // ]; } + + protected function cacheUsePlainKeyValue() + { + return $this->cacheUsePlainKey; + } + + protected function cacheForValue() + { + return 3600; + } } diff --git a/tests/Models/Page.php b/tests/Models/Page.php index d9de9a8..c1f622b 100644 --- a/tests/Models/Page.php +++ b/tests/Models/Page.php @@ -23,4 +23,14 @@ protected function getCacheBaseTags(): array 'test', ]; } + + protected function cacheUsePlainKeyValue() + { + return $this->cacheUsePlainKey; + } + + protected function cacheForValue() + { + return 3600; + } } diff --git a/tests/Models/Post.php b/tests/Models/Post.php index 3454d9c..74d671b 100644 --- a/tests/Models/Post.php +++ b/tests/Models/Post.php @@ -21,4 +21,14 @@ protected function getCacheBaseTags(): array // ]; } + + protected function cacheUsePlainKeyValue() + { + return $this->cacheUsePlainKey; + } + + protected function cacheForValue() + { + return 3600; + } } diff --git a/tests/Models/Role.php b/tests/Models/Role.php index 17500f2..b212b01 100644 --- a/tests/Models/Role.php +++ b/tests/Models/Role.php @@ -21,4 +21,14 @@ protected function getCacheBaseTags(): array // ]; } + + protected function cacheUsePlainKeyValue() + { + return $this->cacheUsePlainKey; + } + + protected function cacheForValue() + { + return 3600; + } } diff --git a/tests/Models/User.php b/tests/Models/User.php index 7901202..adbeae7 100644 --- a/tests/Models/User.php +++ b/tests/Models/User.php @@ -32,6 +32,16 @@ protected function getCacheBaseTags(): array ]; } + protected function cacheUsePlainKeyValue() + { + return $this->cacheUsePlainKey; + } + + protected function cacheForValue() + { + return 3600; + } + public function getCacheTagsToInvalidateOnUpdate($relation = null, $pivotedModels = null): array { if ($relation === 'roles') {