1<?php 2 3namespace dokuwiki\Cache; 4 5/** 6 * Caching of data of renderer 7 */ 8class CacheRenderer extends CacheParser 9{ 10 11 /** 12 * method contains cache use decision logic 13 * 14 * @return bool see useCache() 15 */ 16 public function makeDefaultCacheDecision() 17 { 18 global $conf; 19 20 if (!parent::makeDefaultCacheDecision()) { 21 return false; 22 } 23 24 if (!isset($this->page)) { 25 return true; 26 } 27 28 // meta cache older than file it depends on? 29 if ($this->_time < @filemtime(metaFN($this->page, '.meta'))) { 30 return false; 31 } 32 33 // check current link existence is consistent with cache version 34 // first check the purgefile 35 // - if the cache is more recent than the purgefile we know no links can have been updated 36 if ($this->_time >= @filemtime($conf['cachedir'] . '/purgefile')) { 37 return true; 38 } 39 40 // for wiki pages, check metadata dependencies 41 $metadata = p_get_metadata($this->page); 42 43 if ( 44 !isset($metadata['relation']['references']) || 45 empty($metadata['relation']['references']) 46 ) { 47 return true; 48 } 49 50 foreach ($metadata['relation']['references'] as $id => $exists) { 51 if ($exists != page_exists($id, '', false)) { 52 return false; 53 } 54 } 55 56 return true; 57 } 58 59 protected function addDependencies() 60 { 61 global $conf; 62 63 // default renderer cache file 'age' is dependent on 'cachetime' setting, two special values: 64 // -1 : do not cache (should not be overridden) 65 // 0 : cache never expires (can be overridden) - no need to set depends['age'] 66 if ($conf['cachetime'] == -1) { 67 $this->_nocache = true; 68 return; 69 } elseif ($conf['cachetime'] > 0) { 70 $this->depends['age'] = isset($this->depends['age']) ? 71 min($this->depends['age'], $conf['cachetime']) : $conf['cachetime']; 72 } 73 74 // renderer cache file dependencies ... 75 $files = [DOKU_INC . 'inc/parser/' . $this->mode . '.php']; 76 77 // page implies metadata and possibly some other dependencies 78 if (isset($this->page)) { 79 // for xhtml this will render the metadata if needed 80 $valid = p_get_metadata($this->page, 'date valid'); 81 if (!empty($valid['age'])) { 82 $this->depends['age'] = isset($this->depends['age']) ? 83 min($this->depends['age'], $valid['age']) : $valid['age']; 84 } 85 } 86 87 $this->depends['files'] = empty($this->depends['files']) ? 88 $files : 89 array_merge($files, $this->depends['files']); 90 91 parent::addDependencies(); 92 } 93} 94