MediaWiki
1.33.0
|
APC-backed and APCu-backed function memoization. More...
Public Member Functions | |
__construct ( $callable, $ttl=3600) | |
invoke () | |
Invoke the memoized function or method. More... | |
invokeArgs (array $args=[]) | |
Invoke the memoized function or method. More... | |
Static Public Member Functions | |
static | call ( $callable, array $args=[], $ttl=3600) |
Shortcut method for creating a MemoizedCallable and invoking it with the specified arguments. More... | |
Protected Member Functions | |
fetchResult ( $key, &$success) | |
Fetch the result of a previous invocation from APC or APCu. More... | |
storeResult ( $key, $result) | |
Store the result of an invocation in APC or APCu. More... | |
Private Attributes | |
callable | $callable |
string | $callableName |
Unique name of callable; used for cache keys. More... | |
APC-backed and 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 APC or APCu.
Definition at line 43 of file MemoizedCallable.php.
MemoizedCallable::__construct | ( | $callable, | |
$ttl = 3600 |
|||
) |
InvalidArgumentException | if $callable is not a callable. |
callable | $callable | Function or method to memoize. |
int | $ttl | TTL in seconds. Defaults to 3600 (1hr). Capped at 86400 (24h). |
Definition at line 56 of file MemoizedCallable.php.
References $callable.
|
static |
Shortcut method for creating a MemoizedCallable and invoking it with the specified arguments.
callable | $callable | |
array | $args | |
int | $ttl |
Definition at line 154 of file MemoizedCallable.php.
References $args, and $callable.
Referenced by ResourceLoaderWikiModule\getStyles(), and MemoizedCallableTest\testShortcutMethod().
|
protected |
Fetch the result of a previous invocation from APC or APCu.
string | $key | |
bool | &$success |
Reimplemented in ArrayBackedMemoizedCallable.
Definition at line 80 of file MemoizedCallable.php.
References $success.
Referenced by invokeArgs().
MemoizedCallable::invoke | ( | ) |
Invoke the memoized function or method.
Like MemoizedCallable::invokeArgs(), but variadic.
mixed | $params,... | Parameters for memoized function or method. |
Definition at line 141 of file MemoizedCallable.php.
References invokeArgs().
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 111 of file MemoizedCallable.php.
References $args, $callable, $success, as, fetchResult(), serialize(), and storeResult().
Referenced by invoke(), and MemoizedCallableTest\testMemoizedClosure().
|
protected |
Store the result of an invocation in APC or APCu.
string | $key | |
mixed | $result |
Reimplemented in ArrayBackedMemoizedCallable.
Definition at line 96 of file MemoizedCallable.php.
Referenced by invokeArgs().
|
private |
Definition at line 46 of file MemoizedCallable.php.
Referenced by __construct(), call(), and invokeArgs().
|
private |
Unique name of callable; used for cache keys.
Definition at line 49 of file MemoizedCallable.php.