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.
 
 
 
 
 

64 lines
1.6 KiB

  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. // source doesn't exist
  37. return false;
  38. }
  39. return parent::makeDefaultCacheDecision();
  40. }
  41. protected function addDependencies()
  42. {
  43. // parser cache file dependencies ...
  44. $files = [
  45. $this->file, // source
  46. DOKU_INC . 'inc/Parsing/Parser.php', // parser
  47. DOKU_INC . 'inc/parser/handler.php', // handler
  48. ];
  49. $files = array_merge($files, getConfigFiles('main')); // wiki settings
  50. $this->depends['files'] = empty($this->depends['files']) ?
  51. $files :
  52. array_merge($files, $this->depends['files']);
  53. parent::addDependencies();
  54. }
  55. }