57 if ( !is_callable(
$callable,
false, $this->callableName ) ) {
58 throw new InvalidArgumentException(
59 'Argument 1 passed to MemoizedCallable::__construct() must ' .
60 'be an instance of callable; ' . gettype(
$callable ) .
' given'
64 if ( $this->callableName ===
'Closure::__invoke' ) {
66 $this->callableName .= uniqid();
70 $this->ttl = min( max( $ttl, 1 ), 86400 );
82 if ( function_exists(
'apc_fetch' ) ) {
84 } elseif ( function_exists(
'apcu_fetch' ) ) {
97 if ( function_exists(
'apc_store' ) ) {
98 apc_store( $key, $result, $this->ttl );
99 } elseif ( function_exists(
'apcu_store' ) ) {
100 apcu_store( $key, $result, $this->ttl );
112 foreach (
$args as $arg ) {
113 if ( $arg !==
null && !is_scalar( $arg ) ) {
114 throw new InvalidArgumentException(
115 'MemoizedCallable::invoke() called with non-scalar ' .
122 $key = __CLASS__ .
':' . $this->callableName .
':' . $hash;
126 $result = call_user_func_array( $this->callable,
$args );
156 return $instance->invokeArgs(
$args );
APC-backed and APCu-backed function memoization.
invoke()
Invoke the memoized function or method.
static call( $callable, array $args=[], $ttl=3600)
Shortcut method for creating a MemoizedCallable and invoking it with the specified arguments.
__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.
namespace being checked & $result