Demo\Example\CacheableDemo::getReport PHP Method

getReport() public method

In this example we use "Cacheable" annotation to explicit mark a method
public getReport ( string $from ) : string
$from string This can be any value
return string
    public function getReport($from)
    {
        // long calculation for 100ms
        usleep(0.1 * 1000000.0);
        return $from;
    }

Usage Example

Beispiel #1
0
use Demo\Example\IntroductionDemo;
use Demo\Example\LoggingDemo;
use Demo\Example\PropertyDemo;
use Demo\Example\UserFluentDemo;
use Demo\Highlighter;
use Go\Instrument\Transformer\MagicConstantTransformer;
$isAOPDisabled = isset($_COOKIE['aop_on']) && $_COOKIE['aop_on'] == 'false';
include __DIR__ . ($isAOPDisabled ? '/autoload.php' : '/autoload_aspect.php');
$showCase = isset($_GET['showcase']) ? $_GET['showcase'] : 'default';
$example = null;
$aspectName = '';
switch ($showCase) {
    case 'cacheable':
        $aspectName = 'Demo\\Aspect\\CachingAspect';
        $example = new CacheableDemo();
        $result = $example->getReport(12345);
        // First call will take 0.1 second
        echo "Result is: ", $result, PHP_EOL;
        $result = $example->getReport(12346);
        // This call is cached and result should be '12345'
        echo "Result is: ", $result, PHP_EOL;
        break;
    case 'loggable':
        $aspectName = 'Demo\\Aspect\\LoggingAspect';
        $example = new LoggingDemo();
        $example->execute('LoggingTask');
        // Logging for dynamic methods
        LoggingDemo::runByName('StaticTask');
        // Logging for static methods
        break;
    case 'property-interceptor':
CacheableDemo