PHP code example of ksamborski / apcu-memo

1. Go to this page and download the library: Download ksamborski/apcu-memo library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ksamborski / apcu-memo example snippets



use APCuMemo\APCuMemo;

function sumrange($a, $b)
{
    return APCuMemo::memoize(
        function(...$_) use ($a, $b) {
            return array_reduce(range($a, $b), function ($product, $item) { return $product + $item; }, 1);
        },
        [ 'ttl' => 5 ],
        "sumrange",
        $a,
        $b
    );
}

$start = microtime(true);
echo sumrange((int) $_GET['a'], (int) $_GET['b']);
$elapsed = microtime(true) - $start;
echo " " . ($elapsed * 1000) . " ms";