|
MediaWiki master
|
APCu-backed function memoization. More...
Public Member Functions | |
| __construct ( $callable, $ttl=3600) | |
| invoke (... $params) | |
| Invoke the memoized function or method. | |
| invokeArgs (array $args=[]) | |
| Invoke the memoized function or method. | |
Static Public Member Functions | |
| static | call ( $callable, array $args=[], $ttl=3600) |
| Shortcut method for creating a MemoizedCallable and invoking it with the specified arguments. | |
Protected Member Functions | |
| fetchResult ( $key, &$success) | |
| Fetch the result of a previous invocation. | |
| storeResult ( $key, $result) | |
| Store the result of an invocation. | |
APCu-backed function memoization.
This class provides memoization for pure functions. A function is pure if its result value depends on nothing other than its input parameters and if invoking it does not cause any side-effects.
The first invocation of the memoized callable with a particular set of arguments will be delegated to the underlying callable. Repeat invocations with the same input parameters will be served from APCu.
Definition at line 35 of file MemoizedCallable.php.
| Wikimedia\ObjectCache\MemoizedCallable::__construct | ( | $callable, | |
| $ttl = 3600 ) |
| callable&string|callable&array | $callable Function or method to memoize. This class does not support Closure objects, as it uses the function/method name as a cache key. To memoize a closure, use Wikimedia\ObjectCache\APCUBagOStuff::getWithSetCallback() instead and pass a unique name for your closure and its parameters to makeGlobalKey. | |
| int | $ttl | TTL in seconds. Defaults to 3600 (1 hour). Capped at 86400 (24 hours). |
Definition at line 53 of file MemoizedCallable.php.
|
static |
Shortcut method for creating a MemoizedCallable and invoking it with the specified arguments.
| callable&string|callable&array | $callable | |
| array | $args | |
| int | $ttl |
Definition at line 150 of file MemoizedCallable.php.
|
protected |
Fetch the result of a previous invocation.
| string | $key | |
| bool | &$success |
Definition at line 80 of file MemoizedCallable.php.
References $success.
Referenced by Wikimedia\ObjectCache\MemoizedCallable\invokeArgs().
| Wikimedia\ObjectCache\MemoizedCallable::invoke | ( | $params | ) |
Invoke the memoized function or method.
Like MemoizedCallable::invokeArgs(), but variadic.
| mixed | ...$params Parameters for memoized function or method. |
Definition at line 137 of file MemoizedCallable.php.
References Wikimedia\ObjectCache\MemoizedCallable\invokeArgs().
| Wikimedia\ObjectCache\MemoizedCallable::invokeArgs | ( | array | $args = [] | ) |
Invoke the memoized function or method.
| InvalidArgumentException | If parameters list contains non-scalar items. |
| array | $args | Parameters for memoized function or method. |
Definition at line 107 of file MemoizedCallable.php.
References $success, Wikimedia\ObjectCache\MemoizedCallable\fetchResult(), and Wikimedia\ObjectCache\MemoizedCallable\storeResult().
Referenced by Wikimedia\ObjectCache\MemoizedCallable\invoke().
|
protected |
Store the result of an invocation.
| string | $key | |
| mixed | $result |
Definition at line 94 of file MemoizedCallable.php.
Referenced by Wikimedia\ObjectCache\MemoizedCallable\invokeArgs().