MediaWiki  1.28.0
MemoizedCallable Class Reference
Inheritance diagram for MemoizedCallable:
Collaboration diagram for MemoizedCallable:

Public Member Functions

 __construct ($callable, $ttl=3600)
 Constructor. More...
 
 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...
 

Detailed Description

Definition at line 40 of file MemoizedCallable.php.

Constructor & Destructor Documentation

MemoizedCallable::__construct (   $callable,
  $ttl = 3600 
)

Constructor.

Exceptions
InvalidArgumentExceptionif $callable is not a callable.
Parameters
callable$callableFunction or method to memoize.
int$ttlTTL in seconds. Defaults to 3600 (1hr). Capped at 86400 (24h).

Definition at line 55 of file MemoizedCallable.php.

References $callable.

Member Function Documentation

static MemoizedCallable::call (   $callable,
array  $args = [],
  $ttl = 3600 
)
static

Shortcut method for creating a MemoizedCallable and invoking it with the specified arguments.

Parameters
callable$callable
array$args
int$ttl

Definition at line 151 of file MemoizedCallable.php.

References $args, and $callable.

Referenced by ResourceLoaderWikiModule\getStyles(), and MemoizedCallableTest\testShortcutMethod().

MemoizedCallable::fetchResult (   $key,
$success 
)
protected

Fetch the result of a previous invocation from APC or APCu.

Parameters
string$key
bool&$success

Definition at line 78 of file MemoizedCallable.php.

References $success.

Referenced by invokeArgs().

MemoizedCallable::invoke ( )

Invoke the memoized function or method.

Like MemoizedCallable::invokeArgs(), but variadic.

Parameters
mixed...$params Parameters for memoized function or method.
Returns
mixed The memoized callable's return value.

Definition at line 139 of file MemoizedCallable.php.

References invokeArgs().

MemoizedCallable::invokeArgs ( array  $args = [])

Invoke the memoized function or method.

Exceptions
InvalidArgumentExceptionIf parameters list contains non-scalar items.
Parameters
array$argsParameters for memoized function or method.
Returns
mixed The memoized callable's return value.

Definition at line 109 of file MemoizedCallable.php.

References $args, $success, as, fetchResult(), serialize(), and storeResult().

Referenced by invoke(), and MemoizedCallableTest\testMemoizedClosure().

MemoizedCallable::storeResult (   $key,
  $result 
)
protected

Store the result of an invocation in APC or APCu.

Parameters
string$key
mixed$result

Definition at line 94 of file MemoizedCallable.php.

Referenced by invokeArgs().

Member Data Documentation

callable MemoizedCallable::$callable
private

Definition at line 43 of file MemoizedCallable.php.

Referenced by __construct(), and call().

string MemoizedCallable::$callableName
private

Unique name of callable; used for cache keys.

Definition at line 46 of file MemoizedCallable.php.


The documentation for this class was generated from the following file: