Skip to content

Commit aabf8b9

Browse files
committed
Added methods to cache
1 parent cc7c910 commit aabf8b9

File tree

7 files changed

+80
-0
lines changed

7 files changed

+80
-0
lines changed

src/Traits/QueryCacheable.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,22 +91,42 @@ protected function newBaseQueryBuilder()
9191
$builder->cacheFor($this->cacheFor);
9292
}
9393

94+
if (method_exists($this, 'cacheForValue')) {
95+
$builder->cacheFor($this->cacheForValue($builder));
96+
}
97+
9498
if ($this->cacheTags) {
9599
$builder->cacheTags($this->cacheTags);
96100
}
97101

102+
if (method_exists($this, 'cacheTagsValue')) {
103+
$builder->cacheTags($this->cacheTagsValue($builder));
104+
}
105+
98106
if ($this->cachePrefix) {
99107
$builder->cachePrefix($this->cachePrefix);
100108
}
101109

110+
if (method_exists($this, 'cachePrefixValue')) {
111+
$builder->cachePrefix($this->cachePrefixValue($builder));
112+
}
113+
102114
if ($this->cacheDriver) {
103115
$builder->cacheDriver($this->cacheDriver);
104116
}
105117

118+
if (method_exists($this, 'cacheDriverValue')) {
119+
$builder->cacheDriver($this->cacheDriverValue($builder));
120+
}
121+
106122
if ($this->cacheUsePlainKey) {
107123
$builder->withPlainKey();
108124
}
109125

126+
if (method_exists($this, 'cacheUsePlainKeyValue')) {
127+
$builder->withPlainKey($this->cacheUsePlainKeyValue($builder));
128+
}
129+
110130
return $builder->cacheBaseTags($this->getCacheBaseTags());
111131
}
112132
}

tests/Models/Book.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,14 @@ class Book extends Model
1414
protected $fillable = [
1515
'name',
1616
];
17+
18+
protected function cacheUsePlainKeyValue()
19+
{
20+
return $this->cacheUsePlainKey;
21+
}
22+
23+
protected function cacheForValue()
24+
{
25+
return 3600;
26+
}
1727
}

tests/Models/Kid.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,14 @@ protected function getCacheBaseTags(): array
2121
//
2222
];
2323
}
24+
25+
protected function cacheUsePlainKeyValue()
26+
{
27+
return $this->cacheUsePlainKey;
28+
}
29+
30+
protected function cacheForValue()
31+
{
32+
return 3600;
33+
}
2434
}

tests/Models/Page.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,14 @@ protected function getCacheBaseTags(): array
2323
'test',
2424
];
2525
}
26+
27+
protected function cacheUsePlainKeyValue()
28+
{
29+
return $this->cacheUsePlainKey;
30+
}
31+
32+
protected function cacheForValue()
33+
{
34+
return 3600;
35+
}
2636
}

tests/Models/Post.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,14 @@ protected function getCacheBaseTags(): array
2121
//
2222
];
2323
}
24+
25+
protected function cacheUsePlainKeyValue()
26+
{
27+
return $this->cacheUsePlainKey;
28+
}
29+
30+
protected function cacheForValue()
31+
{
32+
return 3600;
33+
}
2434
}

tests/Models/Role.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,14 @@ protected function getCacheBaseTags(): array
2121
//
2222
];
2323
}
24+
25+
protected function cacheUsePlainKeyValue()
26+
{
27+
return $this->cacheUsePlainKey;
28+
}
29+
30+
protected function cacheForValue()
31+
{
32+
return 3600;
33+
}
2434
}

tests/Models/User.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ protected function getCacheBaseTags(): array
3232
];
3333
}
3434

35+
protected function cacheUsePlainKeyValue()
36+
{
37+
return $this->cacheUsePlainKey;
38+
}
39+
40+
protected function cacheForValue()
41+
{
42+
return 3600;
43+
}
44+
3545
public function getCacheTagsToInvalidateOnUpdate($relation = null, $pivotedModels = null): array
3646
{
3747
if ($relation === 'roles') {

0 commit comments

Comments
 (0)