Skip to content

Commit 73e21c6

Browse files
committed
Clean up CacheBuilder class a bit
1 parent 3d59b36 commit 73e21c6

File tree

1 file changed

+16
-39
lines changed

1 file changed

+16
-39
lines changed

src/CachedBuilder.php

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ public function avg($column)
1616
return parent::avg($column);
1717
}
1818

19-
$arguments = func_get_args();
2019
$cacheKey = $this->makeCacheKey(["*"], null, "-avg_{$column}");
21-
$method = "avg";
2220

23-
return $this->cachedValue($arguments, $cacheKey, $method);
21+
return $this->cachedValue(func_get_args(), $cacheKey);
2422
}
2523

2624
public function count($columns = ["*"])
@@ -29,11 +27,9 @@ public function count($columns = ["*"])
2927
return parent::count($columns);
3028
}
3129

32-
$arguments = func_get_args();
33-
$cacheKey = $this->makeCacheKey(["*"], null, "-count");
34-
$method = "count";
30+
$cacheKey = $this->makeCacheKey($columns, null, "-count");
3531

36-
return $this->cachedValue($arguments, $cacheKey, $method);
32+
return $this->cachedValue(func_get_args(), $cacheKey);
3733
}
3834

3935
public function cursor()
@@ -42,11 +38,9 @@ public function cursor()
4238
return collect(parent::cursor());
4339
}
4440

45-
$arguments = func_get_args();
4641
$cacheKey = $this->makeCacheKey(["*"], null, "-cursor");
47-
$method = "cursor";
4842

49-
return $this->cachedValue($arguments, $cacheKey, $method);
43+
return $this->cachedValue(func_get_args(), $cacheKey);
5044
}
5145

5246
public function delete()
@@ -66,11 +60,9 @@ public function find($id, $columns = ["*"])
6660
return parent::find($id, $columns);
6761
}
6862

69-
$arguments = func_get_args();
70-
$cacheKey = $this->makeCacheKey(["*"], null, "-find_{$id}");
71-
$method = "find";
63+
$cacheKey = $this->makeCacheKey($columns, null, "-find_{$id}");
7264

73-
return $this->cachedValue($arguments, $cacheKey, $method);
65+
return $this->cachedValue(func_get_args(), $cacheKey);
7466
}
7567

7668
public function first($columns = ["*"])
@@ -79,11 +71,9 @@ public function first($columns = ["*"])
7971
return parent::first($columns);
8072
}
8173

82-
$arguments = func_get_args();
8374
$cacheKey = $this->makeCacheKey($columns);
84-
$method = "first";
8575

86-
return $this->cachedValue($arguments, $cacheKey, $method);
76+
return $this->cachedValue(func_get_args(), $cacheKey);
8777
}
8878

8979
public function get($columns = ["*"])
@@ -92,11 +82,9 @@ public function get($columns = ["*"])
9282
return parent::get($columns);
9383
}
9484

95-
$arguments = func_get_args();
9685
$cacheKey = $this->makeCacheKey($columns);
97-
$method = "get";
9886

99-
return $this->cachedValue($arguments, $cacheKey, $method);
87+
return $this->cachedValue(func_get_args(), $cacheKey);
10088
}
10189

10290
public function max($column)
@@ -105,11 +93,9 @@ public function max($column)
10593
return parent::max($column);
10694
}
10795

108-
$arguments = func_get_args();
10996
$cacheKey = $this->makeCacheKey(["*"], null, "-max_{$column}");
110-
$method = "max";
11197

112-
return $this->cachedValue($arguments, $cacheKey, $method);
98+
return $this->cachedValue(func_get_args(), $cacheKey);
11399
}
114100

115101
public function min($column)
@@ -118,11 +104,9 @@ public function min($column)
118104
return parent::min($column);
119105
}
120106

121-
$arguments = func_get_args();
122107
$cacheKey = $this->makeCacheKey(["*"], null, "-min_{$column}");
123-
$method = "min";
124108

125-
return $this->cachedValue($arguments, $cacheKey, $method);
109+
return $this->cachedValue(func_get_args(), $cacheKey);
126110
}
127111

128112
public function paginate(
@@ -135,12 +119,10 @@ public function paginate(
135119
return parent::paginate($perPage, $columns, $pageName, $page);
136120
}
137121

138-
$arguments = func_get_args();
139122
$page = $page ?: 1;
140123
$cacheKey = $this->makeCacheKey($columns, null, "-paginate_by_{$perPage}_{$pageName}_{$page}");
141-
$method = "paginate";
142124

143-
return $this->cachedValue($arguments, $cacheKey, $method);
125+
return $this->cachedValue(func_get_args(), $cacheKey);
144126
}
145127

146128
public function pluck($column, $key = null)
@@ -150,11 +132,9 @@ public function pluck($column, $key = null)
150132
}
151133

152134
$keyDifferentiator = "-pluck_{$column}" . ($key ? "_{$key}" : "");
153-
$arguments = func_get_args();
154135
$cacheKey = $this->makeCacheKey([$column], null, $keyDifferentiator);
155-
$method = "pluck";
156136

157-
return $this->cachedValue($arguments, $cacheKey, $method);
137+
return $this->cachedValue(func_get_args(), $cacheKey);
158138
}
159139

160140
public function sum($column)
@@ -163,11 +143,9 @@ public function sum($column)
163143
return parent::sum($column);
164144
}
165145

166-
$arguments = func_get_args();
167146
$cacheKey = $this->makeCacheKey(["*"], null, "-sum_{$column}");
168-
$method = "sum";
169147

170-
return $this->cachedValue($arguments, $cacheKey, $method);
148+
return $this->cachedValue(func_get_args(), $cacheKey);
171149
}
172150

173151
public function value($column)
@@ -176,15 +154,14 @@ public function value($column)
176154
return parent::value($column);
177155
}
178156

179-
$arguments = func_get_args();
180157
$cacheKey = $this->makeCacheKey(["*"], null, "-value_{$column}");
181-
$method = "value";
182158

183-
return $this->cachedValue($arguments, $cacheKey, $method);
159+
return $this->cachedValue(func_get_args(), $cacheKey);
184160
}
185161

186-
public function cachedValue(array $arguments, string $cacheKey, string $method)
162+
public function cachedValue(array $arguments, string $cacheKey)
187163
{
164+
$method = debug_backtrace()[1]['function'];
188165
$cacheTags = $this->makeCacheTags();
189166
$hashedCacheKey = sha1($cacheKey);
190167
$result = $this->retrieveCachedValue(

0 commit comments

Comments
 (0)