Skip to content

Commit c3ffc32

Browse files
committed
code consistency fixes
1 parent 3e491d8 commit c3ffc32

File tree

9 files changed

+41
-31
lines changed

9 files changed

+41
-31
lines changed

src/Traits/QueryCacheModule.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public function flushQueryCacheWithTag(string $tag): bool
205205
* Indicate that the query results should be cached.
206206
*
207207
* @param \DateTime|int $time
208-
* @return \Rennokki\QueryCache\Query\Builder
208+
* @return \Rennokki\QueryCache\Traits\QueryCacheModule
209209
*/
210210
public function cacheFor($time)
211211
{
@@ -253,7 +253,7 @@ public function doNotCache(bool $avoidCache = true)
253253
* Set the cache prefix.
254254
*
255255
* @param string $prefix
256-
* @return \Rennokki\QueryCache\Query\Builder
256+
* @return \Rennokki\QueryCache\Traits\QueryCacheModule
257257
*/
258258
public function cachePrefix(string $prefix)
259259
{
@@ -266,7 +266,7 @@ public function cachePrefix(string $prefix)
266266
* Attach tags to the cache.
267267
*
268268
* @param array $cacheTags
269-
* @return \Rennokki\QueryCache\Query\Builder
269+
* @return \Rennokki\QueryCache\Traits\QueryCacheModule
270270
*/
271271
public function cacheTags(array $cacheTags = [])
272272
{
@@ -279,7 +279,7 @@ public function cacheTags(array $cacheTags = [])
279279
* Append tags to the cache.
280280
*
281281
* @param array $cacheTags
282-
* @return \Rennokki\QueryCache\Query\Builder
282+
* @return \Rennokki\QueryCache\Traits\QueryCacheModule
283283
*/
284284
public function appendCacheTags(array $cacheTags = [])
285285
{
@@ -292,7 +292,7 @@ public function appendCacheTags(array $cacheTags = [])
292292
* Use a specific cache driver.
293293
*
294294
* @param string $cacheDriver
295-
* @return \Rennokki\QueryCache\Query\Builder
295+
* @return \Rennokki\QueryCache\Traits\QueryCacheModule
296296
*/
297297
public function cacheDriver(string $cacheDriver)
298298
{
@@ -306,7 +306,7 @@ public function cacheDriver(string $cacheDriver)
306306
* that will be present on all cached queries.
307307
*
308308
* @param array $tags
309-
* @return \Rennokki\QueryCache\Query\Builder
309+
* @return \Rennokki\QueryCache\Traits\QueryCacheModule
310310
*/
311311
public function cacheBaseTags(array $tags = [])
312312
{
@@ -318,7 +318,7 @@ public function cacheBaseTags(array $tags = [])
318318
/**
319319
* Use a plain key instead of a hashed one in the cache driver.
320320
*
321-
* @return \Rennokki\QueryCache\Query\Builder
321+
* @return \Rennokki\QueryCache\Traits\QueryCacheModule
322322
*/
323323
public function withPlainKey()
324324
{

src/Traits/QueryCacheable.php

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,28 @@
1414
*/
1515
trait QueryCacheable
1616
{
17+
/**
18+
* Invalidate the cache automatically
19+
* upon update in the database.
20+
*
21+
* @var bool
22+
*/
23+
protected static $flushCacheOnUpdate = false;
24+
25+
/**
26+
* Boot the trait.
27+
*
28+
* @return void
29+
*/
30+
public static function bootQueryCacheable()
31+
{
32+
if (isset(static::$flushCacheOnUpdate) && static::$flushCacheOnUpdate) {
33+
static::observe(
34+
static::getFlushQueryCacheObserver()
35+
);
36+
}
37+
}
38+
1739
/**
1840
* Get the observer class name that will
1941
* observe the changes and will invalidate the cache
@@ -37,20 +59,6 @@ public function getCacheTagsToInvalidateOnUpdate(): array
3759
return $this->getCacheBaseTags();
3860
}
3961

40-
/**
41-
* Boot the trait.
42-
*
43-
* @return void
44-
*/
45-
public static function bootQueryCacheable()
46-
{
47-
if (isset(static::$flushCacheOnUpdate) && static::$flushCacheOnUpdate) {
48-
static::observe(
49-
static::getFlushQueryCacheObserver()
50-
);
51-
}
52-
}
53-
5462
/**
5563
* {@inheritdoc}
5664
*/
@@ -64,9 +72,11 @@ protected function newBaseQueryBuilder()
6472
$connection->getPostProcessor()
6573
);
6674

67-
$this->cacheFor
68-
? $builder->cacheFor($this->cacheFor)
69-
: $builder->dontCache();
75+
$builder->dontCache();
76+
77+
if ($this->cacheFor) {
78+
$builder->cacheFor($this->cacheFor);
79+
}
7080

7181
if ($this->cacheTags) {
7282
$builder->cacheTags($this->cacheTags);

tests/CountTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Rennokki\QueryCache\Test;
44

5-
use Cache;
5+
use Illuminate\Support\Facades\Cache;
66
use Rennokki\QueryCache\Test\Models\Post;
77

88
class CountTest extends TestCase

tests/FirstTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Rennokki\QueryCache\Test;
44

5-
use Cache;
5+
use Illuminate\Support\Facades\Cache;
66
use Rennokki\QueryCache\Test\Models\Post;
77

88
class FirstTest extends TestCase

tests/GetTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Rennokki\QueryCache\Test;
44

5-
use Cache;
5+
use Illuminate\Support\Facades\Cache;
66
use Rennokki\QueryCache\Test\Models\Post;
77

88
class GetTest extends TestCase

tests/MethodsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Rennokki\QueryCache\Test;
44

5-
use Cache;
5+
use Illuminate\Support\Facades\Cache;
66
use Rennokki\QueryCache\Test\Models\Book;
77
use Rennokki\QueryCache\Test\Models\Kid;
88
use Rennokki\QueryCache\Test\Models\Post;

tests/PaginateTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Rennokki\QueryCache\Test;
44

5-
use Cache;
5+
use Illuminate\Support\Facades\Cache;
66
use Rennokki\QueryCache\Test\Models\Post;
77

88
class PaginateTest extends TestCase

tests/SimplePaginateTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Rennokki\QueryCache\Test;
44

5-
use Cache;
5+
use Illuminate\Support\Facades\Cache;
66
use Rennokki\QueryCache\Test\Models\Post;
77

88
class SimplePaginateTest extends TestCase

tests/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Rennokki\QueryCache\Test;
44

5-
use Cache;
5+
use Illuminate\Support\Facades\Cache;
66
use Orchestra\Testbench\TestCase as Orchestra;
77

88
abstract class TestCase extends Orchestra

0 commit comments

Comments
 (0)