summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--_test/tests/inc/cache_stalecheck.test.php27
-rw-r--r--inc/cache.php7
-rw-r--r--inc/parserutils.php3
3 files changed, 32 insertions, 5 deletions
diff --git a/_test/tests/inc/cache_stalecheck.test.php b/_test/tests/inc/cache_stalecheck.test.php
new file mode 100644
index 000000000..93f44a55c
--- /dev/null
+++ b/_test/tests/inc/cache_stalecheck.test.php
@@ -0,0 +1,27 @@
+<?php
+
+class cache_stalecheck_test extends DokuWikiTest {
+ function test_staleness() {
+ global $ID;
+
+ $ID = 'stale';
+ $file = wikiFN($ID);
+
+ # Prepare test page
+ saveWikiText($ID, 'Fresh', 'Created');
+
+ # Create stale cache
+ $cache = new cache_renderer($ID, $file, 'xhtml');
+ $cache->storeCache('Stale');
+ $stale = $cache->retrieveCache();
+
+ # Prepare stale cache for testing
+ $time = filemtime($file);
+ touch($cache->cache, $time);
+
+ # Make the test
+ $fresh = p_cached_output($file, 'xhtml', $ID);
+ $this->assertNotEquals($fresh, $stale, 'Stale cache failed to expire');
+ }
+}
+
diff --git a/inc/cache.php b/inc/cache.php
index 204c6f006..5eac94934 100644
--- a/inc/cache.php
+++ b/inc/cache.php
@@ -69,7 +69,7 @@ class cache {
if (!empty($this->depends['files'])) {
foreach ($this->depends['files'] as $file) {
- if ($this->_time < @filemtime($file)) return false; // cache older than files it depends on?
+ if ($this->_time <= @filemtime($file)) return false; // cache older than files it depends on?
}
}
@@ -207,6 +207,8 @@ class cache_renderer extends cache_parser {
return true;
}
+ if ($this->_time < @filemtime(metaFN($this->page,'.meta'))) return false; // meta cache older than file it depends on?
+
// 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
@@ -239,9 +241,6 @@ class cache_renderer extends cache_parser {
// page implies metadata and possibly some other dependencies
if (isset($this->page)) {
- $metafile = metaFN($this->page,'.meta');
- $files[] = $metafile; // ... the page's own metadata
-
$valid = p_get_metadata($this->page, 'date valid'); // for xhtml this will render the metadata if needed
if (!empty($valid['age'])) {
$this->depends['age'] = isset($this->depends['age']) ?
diff --git a/inc/parserutils.php b/inc/parserutils.php
index 25d7cf131..55b451c76 100644
--- a/inc/parserutils.php
+++ b/inc/parserutils.php
@@ -318,8 +318,9 @@ function p_get_metadata($id, $key='', $render=METADATA_RENDER_USING_CACHE){
// only update the file when the metadata has been changed
if ($meta == $old_meta || p_save_metadata($id, $meta)) {
// store a timestamp in order to make sure that the cachefile is touched
+ // this timestamp is also stored when the meta data is still the same
$cachefile->storeCache(time());
- } elseif ($meta != $old_meta) {
+ } else {
msg('Unable to save metadata file. Hint: disk full; file permissions; safe_mode setting.',-1);
}
}