示例#1
0
 public function testHelper()
 {
     Memoize::add(array(array('name' => 'li3_memoize\\tests\\mocks\\Prose', 'method' => array('slowSpeak'))));
     $prose = new Prose();
     $oldClass = get_class($prose);
     Memoize::catchHelper($prose);
     $this->assertNotEqual($oldClass, get_class($prose));
 }
示例#2
0
 public function testSpeedSteady()
 {
     // Filtering
     Memoize::add(array(array('name' => 'li3_memoize\\tests\\mocks\\Prose', 'method' => array('doesNotExist'))));
     // Helper
     $prose = new Prose();
     Memoize::catchHelper($prose);
     // Timing
     $times = array();
     $times[0] = microtime(true);
     $results[0] = $prose->slowSpeak('lithium');
     $times[1] = microtime(true);
     $results[1] = $prose->slowSpeak('lithium');
     $times[2] = microtime(true);
     // The first iteration needs to be MORE than a second
     $this->assertTrue($times[1] - $times[0] > 1);
     // The second needs to be LESS than a second
     $this->assertTrue($times[2] - $times[1] < 1);
     // Results should equal
     $this->assertEqual($results[0], $results[1]);
 }
示例#3
0
<?php

use lithium\util\collection\Filters;
use li3_memoize\extensions\Memoize;
/**
 * Filters the creation of helpers/models
 */
Filters::apply('lithium\\core\\Libraries', 'instance', function ($self, $params, $chain) {
    // Prescan Model
    if (isset($params['options']['model'])) {
        Memoize::catchModel($self, $params, $chain);
    }
    $object = $chain->next($self, $params, $chain);
    // Postscan Helper
    if ($params['type'] == 'helper') {
        Memoize::catchHelper($object);
    }
    return $object;
});