You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

93 lines
2.8 KiB

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