Skip to content

Commit ff40784

Browse files
committed
Cache: used typehint 'callable' (suppresses lazyloading of classes)
1 parent b3ac6cd commit ff40784

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/Caching/Cache.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
namespace Nette\Caching;
99

1010
use Nette;
11-
use Nette\Utils\Callback;
1211

1312

1413
/**
@@ -83,10 +82,9 @@ public function derive($namespace)
8382
/**
8483
* Reads the specified item from the cache or generate it.
8584
* @param mixed
86-
* @param callable
8785
* @return mixed
8886
*/
89-
public function load($key, $fallback = null)
87+
public function load($key, callable $fallback = null)
9088
{
9189
$data = $this->storage->read($this->generateKey($key));
9290
if ($data === null && $fallback) {
@@ -101,10 +99,9 @@ public function load($key, $fallback = null)
10199
/**
102100
* Reads multiple items from the cache.
103101
* @param array
104-
* @param callable
105102
* @return array
106103
*/
107-
public function bulkLoad(array $keys, $fallback = null)
104+
public function bulkLoad(array $keys, callable $fallback = null)
108105
{
109106
if (count($keys) === 0) {
110107
return [];
@@ -273,27 +270,25 @@ public function clean(array $conditions = null)
273270

274271
/**
275272
* Caches results of function/method calls.
276-
* @param mixed
277273
* @return mixed
278274
*/
279-
public function call($function)
275+
public function call(callable $function)
280276
{
281277
$key = func_get_args();
282278
if (is_array($function) && is_object($function[0])) {
283279
$key[0][0] = get_class($function[0]);
284280
}
285281
return $this->load($key, function () use ($function, $key) {
286-
return Callback::invokeArgs($function, array_slice($key, 1));
282+
return call_user_func_array($function, array_slice($key, 1));
287283
});
288284
}
289285

290286

291287
/**
292288
* Caches results of function/method calls.
293-
* @param mixed
294289
* @return \Closure
295290
*/
296-
public function wrap($function, array $dependencies = null)
291+
public function wrap(callable $function, array $dependencies = null)
297292
{
298293
return function () use ($function, $dependencies) {
299294
$key = [$function, func_get_args()];
@@ -302,7 +297,7 @@ public function wrap($function, array $dependencies = null)
302297
}
303298
$data = $this->load($key);
304299
if ($data === null) {
305-
$data = $this->save($key, Callback::invokeArgs($function, $key[1]), $dependencies);
300+
$data = $this->save($key, call_user_func_array($function, $key[1]), $dependencies);
306301
}
307302
return $data;
308303
};

0 commit comments

Comments
 (0)