60 if ( !is_callable(
$callable,
false, $this->callableName ) ) {
61 throw new InvalidArgumentException(
62 'Argument 1 passed to MemoizedCallable::__construct() must ' .
63 'be an instance of callable; ' . gettype(
$callable ) .
' given'
67 if ( $this->callableName ===
'Closure::__invoke' ) {
69 $this->callableName .= uniqid();
73 $this->ttl = min( max(
$ttl, 1 ), 86400 );
85 if ( function_exists(
'apc_fetch' ) ) {
87 } elseif ( function_exists(
'apcu_fetch' ) ) {
100 if ( function_exists(
'apc_store' ) ) {
101 apc_store( $key, $result, $this->ttl );
102 } elseif ( function_exists(
'apcu_store' ) ) {
103 apcu_store( $key, $result, $this->ttl );
115 foreach (
$args as $arg ) {
116 if ( $arg !==
null && !is_scalar( $arg ) ) {
117 throw new InvalidArgumentException(
118 'MemoizedCallable::invoke() called with non-scalar ' .
125 $key = __CLASS__ .
':' . $this->callableName .
':' . $hash;
159 return $instance->invokeArgs(
$args );
APC-backed and APCu-backed function memoization.
static call( $callable, array $args=[], $ttl=3600)
Shortcut method for creating a MemoizedCallable and invoking it with the specified arguments.
invoke(... $params)
Invoke the memoized function or method.
__construct( $callable, $ttl=3600)
fetchResult( $key, &$success)
Fetch the result of a previous invocation from APC or APCu.
string $callableName
Unique name of callable; used for cache keys.
invokeArgs(array $args=[])
Invoke the memoized function or method.
storeResult( $key, $result)
Store the result of an invocation in APC or APCu.