diff options
author | Andreas Gohr <gohr@cosmocode.de> | 2019-10-10 09:55:14 +0200 |
---|---|---|
committer | Andreas Gohr <gohr@cosmocode.de> | 2019-10-10 09:55:14 +0200 |
commit | 31a58aba4c24b34c34ad5764d1a35b7c398c3a2c (patch) | |
tree | 7f4d1546fbb69863a7d366fc1ff647f784853b68 /inc/Cache/CacheRenderer.php | |
parent | af7ba5aa0bd10fc0ad9ef983006305b4c5a8ed42 (diff) | |
parent | c0c77cd20b23921c9e893bb70b99f38be153875a (diff) | |
download | dokuwiki-31a58aba4c24b34c34ad5764d1a35b7c398c3a2c.tar.gz dokuwiki-31a58aba4c24b34c34ad5764d1a35b7c398c3a2c.zip |
Merge branch 'psr2'
* psr2: (160 commits)
fixed merge error
Moved parts of the Asian word handling to its own class
ignore snake_case error of substr_replace
fixed some line length errors
ignore PSR2 in the old form class
fix PSR2 error in switch statement
replaced deprecated utf8 functions
formatting cleanup
mark old utf8 functions deprecated
some more PSR2 cleanup
Some cleanup for the UTF-8 stuff
Moved all utf8 methods to their own namespaced classes
Create separate table files for UTF-8 handling
Ignore mixed concerns in loader
Use type safe comparisons in loader
Remove obsolete include
adjust phpcs exclude patterns for new plugin classes
🚚 Move Subscription class to deprecated.php
♻️ Split up ChangesSubscriptionSender into multiple classes
Minor optimizations in PluginController
...
Diffstat (limited to 'inc/Cache/CacheRenderer.php')
-rw-r--r-- | inc/Cache/CacheRenderer.php | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/inc/Cache/CacheRenderer.php b/inc/Cache/CacheRenderer.php new file mode 100644 index 000000000..e8a28c309 --- /dev/null +++ b/inc/Cache/CacheRenderer.php @@ -0,0 +1,94 @@ +<?php + +namespace dokuwiki\Cache; + +/** + * Caching of data of renderer + */ +class CacheRenderer extends CacheParser +{ + + /** + * method contains cache use decision logic + * + * @return bool see useCache() + */ + public function makeDefaultCacheDecision() + { + global $conf; + + if (!parent::makeDefaultCacheDecision()) { + return false; + } + + if (!isset($this->page)) { + return true; + } + + // meta cache older than file it depends on? + if ($this->_time < @filemtime(metaFN($this->page, '.meta'))) { + return false; + } + + // check current link existence is consistent with cache version + // first check the purgefile + // - if the cache is more recent than the purgefile we know no links can have been updated + if ($this->_time >= @filemtime($conf['cachedir'] . '/purgefile')) { + return true; + } + + // for wiki pages, check metadata dependencies + $metadata = p_get_metadata($this->page); + + if (!isset($metadata['relation']['references']) || + empty($metadata['relation']['references'])) { + return true; + } + + foreach ($metadata['relation']['references'] as $id => $exists) { + if ($exists != page_exists($id, '', false)) { + return false; + } + } + + return true; + } + + protected function addDependencies() + { + global $conf; + + // default renderer cache file 'age' is dependent on 'cachetime' setting, two special values: + // -1 : do not cache (should not be overridden) + // 0 : cache never expires (can be overridden) - no need to set depends['age'] + if ($conf['cachetime'] == -1) { + $this->_nocache = true; + return; + } elseif ($conf['cachetime'] > 0) { + $this->depends['age'] = isset($this->depends['age']) ? + min($this->depends['age'], $conf['cachetime']) : $conf['cachetime']; + } + + // renderer cache file dependencies ... + $files = array( + DOKU_INC . 'inc/parser/' . $this->mode . '.php', // ... the renderer + ); + + // page implies metadata and possibly some other dependencies + if (isset($this->page)) { + + // for xhtml this will render the metadata if needed + $valid = p_get_metadata($this->page, 'date valid'); + if (!empty($valid['age'])) { + $this->depends['age'] = isset($this->depends['age']) ? + min($this->depends['age'], $valid['age']) : $valid['age']; + } + } + + $this->depends['files'] = !empty($this->depends['files']) ? + array_merge($files, $this->depends['files']) : + $files; + + parent::addDependencies(); + } +} |