public function run() { if ($this->has_run) { return true; } //at this point, all the headers are parsed and we haven't run the report yet foreach ($this->headers as $header) { $classname = $header . 'Header'; $classname::afterParse($this); } //record how long it takes to run the report $start = microtime(true); if ($this->is_ready && !$this->async) { //if the report is cached if ($options = $this->retrieveFromCache()) { $this->options = $options; $this->options['FromCache'] = true; } else { $this->_runReport(); $this->prepareDataSets(); $this->storeInCache(); } //add this to the list of recently run reports $recently_run_key = FileSystemCache::generateCacheKey('recently_run'); $recently_run = FileSystemCache::retrieve($recently_run_key); if ($recently_run === false) { $recently_run = array(); } array_unshift($recently_run, $this->report); if (count($recently_run) > 200) { $recently_run = array_slice($recently_run, 0, 200); } FileSystemCache::store($recently_run_key, $recently_run); } //call the beforeRender callback for each header foreach ($this->headers as $header) { $classname = $header . 'Header'; $classname::beforeRender($this); } $this->options['Time'] = round(microtime(true) - $start, 5); if ($this->is_ready && !$this->async && !isset($this->options['FromCache'])) { //get current report times for this report $report_times = FileSystemCache::retrieve($this->getReportTimesCacheKey()); if (!$report_times) { $report_times = array(); } //only keep the last 10 times for each report //this keeps the timing data up to date and relevant if (count($report_times) > 10) { array_shift($report_times); } //store report times $report_times[] = $this->options['Time']; FileSystemCache::store($this->getReportTimesCacheKey(), $report_times); } $this->has_run = true; }
protected static function getReportHeaders($report) { $cacheKey = FileSystemCache::generateCacheKey($report, 'report_headers'); //check if report data is cached and newer than when the report file was created //the url parameter ?nocache will bypass this and not use cache $data = false; if (!isset($_REQUEST['nocache'])) { $data = FileSystemCache::retrieve($cacheKey, filemtime(Report::getFileLocation($report))); } //report data not cached, need to parse it if ($data === false) { $temp = new Report($report); $data = $temp->options; $data['report'] = $report; $data['url'] = self::$request->base . '/report/html/?report=' . $report; $data['is_dir'] = false; $data['Id'] = str_replace(array('_', '-', '/', ' ', '.'), array('', '', '_', '-', '_'), trim($report, '/')); if (!isset($data['Name'])) { $data['Name'] = ucwords(str_replace(array('_', '-'), ' ', basename($report))); } //store parsed report in cache FileSystemCache::store($cacheKey, $data); } return $data; }
function testGroupInvalidationRecursive() { $key_root = FileSystemCache::generateCacheKey('mykey'); $key_group1 = FileSystemCache::generateCacheKey('mykey1', 'test'); $key_group2 = FileSystemCache::generateCacheKey('mykey2', 'test'); $key_sub = FileSystemCache::generateCacheKey('mykey', 'test/test'); $key_other = FileSystemCache::generateCacheKey('mykey', 'test2'); $data = 'group invalidation recursive'; FileSystemCache::store($key_root, $data); FileSystemCache::store($key_group1, $data); FileSystemCache::store($key_group2, $data); FileSystemCache::store($key_sub, $data); FileSystemCache::store($key_other, $data); $this->assertEquals($data, FileSystemCache::retrieve($key_root)); $this->assertEquals($data, FileSystemCache::retrieve($key_group1)); $this->assertEquals($data, FileSystemCache::retrieve($key_group2)); $this->assertEquals($data, FileSystemCache::retrieve($key_sub)); $this->assertEquals($data, FileSystemCache::retrieve($key_other)); FileSystemCache::invalidateGroup('test'); $this->assertEquals($data, FileSystemCache::retrieve($key_root)); $this->assertFalse(FileSystemCache::retrieve($key_group1)); $this->assertFalse(FileSystemCache::retrieve($key_group2)); $this->assertFalse(FileSystemCache::retrieve($key_sub)); $this->assertEquals($data, FileSystemCache::retrieve($key_other)); FileSystemCache::invalidate($key_root); FileSystemCache::invalidate($key_other); $this->assertFalse(FileSystemCache::retrieve($key_root)); $this->assertFalse(FileSystemCache::retrieve($key_other)); }