CacheParser.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace dokuwiki\Cache;
  3. /**
  4. * Parser caching
  5. */
  6. class CacheParser extends Cache
  7. {
  8. public $file = ''; // source file for cache
  9. public $mode = ''; // input mode (represents the processing the input file will undergo)
  10. public $page = '';
  11. /**
  12. *
  13. * @param string $id page id
  14. * @param string $file source file for cache
  15. * @param string $mode input mode
  16. */
  17. public function __construct($id, $file, $mode)
  18. {
  19. global $INPUT;
  20. if ($id) {
  21. $this->page = $id;
  22. }
  23. $this->file = $file;
  24. $this->mode = $mode;
  25. $this->setEvent('PARSER_CACHE_USE');
  26. parent::__construct($file . $INPUT->server->str('HTTP_HOST') . $INPUT->server->str('SERVER_PORT'), '.' . $mode);
  27. }
  28. /**
  29. * method contains cache use decision logic
  30. *
  31. * @return bool see useCache()
  32. */
  33. public function makeDefaultCacheDecision()
  34. {
  35. if (!file_exists($this->file)) {
  36. return false;
  37. } // source exists?
  38. return parent::makeDefaultCacheDecision();
  39. }
  40. protected function addDependencies()
  41. {
  42. // parser cache file dependencies ...
  43. $files = array(
  44. $this->file, // ... source
  45. DOKU_INC . 'inc/Parsing/Parser.php', // ... parser
  46. DOKU_INC . 'inc/parser/handler.php', // ... handler
  47. );
  48. $files = array_merge($files, getConfigFiles('main')); // ... wiki settings
  49. $this->depends['files'] = !empty($this->depends['files']) ?
  50. array_merge($files, $this->depends['files']) :
  51. $files;
  52. parent::addDependencies();
  53. }
  54. }