Should address issue #38 where some people are not getting cache clears

This commit is contained in:
Andy Miller
2014-08-29 14:42:50 -06:00
parent a737cfc2ec
commit 365f7bb596
4 changed files with 17 additions and 4 deletions

View File

@@ -66,6 +66,9 @@ class Cache extends Getters
$this->key = substr(md5(($prefix ? $prefix : 'g') . $uri->rootUrl(true) . $this->config->key . GRAV_VERSION), 2, 8); $this->key = substr(md5(($prefix ? $prefix : 'g') . $uri->rootUrl(true) . $this->config->key . GRAV_VERSION), 2, 8);
$this->driver = $this->getCacheDriver(); $this->driver = $this->getCacheDriver();
// Set the cache namespace to our unique key
$this->driver->setNamespace($this->key);
} }
/** /**
@@ -132,7 +135,6 @@ class Cache extends Getters
public function fetch($id) public function fetch($id)
{ {
if ($this->enabled) { if ($this->enabled) {
$id = $this->key . $id;
return $this->driver->fetch($id); return $this->driver->fetch($id);
} else { } else {
return false; return false;
@@ -149,7 +151,6 @@ class Cache extends Getters
public function save($id, $data, $lifetime = null) public function save($id, $data, $lifetime = null)
{ {
if ($this->enabled) { if ($this->enabled) {
$id = $this->key . $id;
$this->driver->save($id, $data, $lifetime); $this->driver->save($id, $data, $lifetime);
} }
} }

View File

@@ -56,7 +56,6 @@ abstract class Folder
} }
} }
return $last_modified; return $last_modified;
} }

View File

@@ -106,7 +106,7 @@ class Page
public function init($file) public function init($file)
{ {
$this->filePath($file->getPathName()); $this->filePath($file->getPathName());
$this->modified(filemtime($file->getPath())); $this->modified($file->getMTime());
$this->id($this->modified().md5($this->filePath())); $this->id($this->modified().md5($this->filePath()));
$this->header(); $this->header();
$this->slug(); $this->slug();

View File

@@ -426,10 +426,17 @@ class Pages
throw new \RuntimeException('Fatal error when creating page instances.'); throw new \RuntimeException('Fatal error when creating page instances.');
} }
$last_modified = 0;
/** @var \DirectoryIterator $file */ /** @var \DirectoryIterator $file */
foreach ($iterator as $file) { foreach ($iterator as $file) {
$name = $file->getFilename(); $name = $file->getFilename();
$date = $file->getMTime();
if ($date > $last_modified) {
$last_modified = $date;
}
if ($file->isFile() && Utils::endsWith($name, CONTENT_EXT)) { if ($file->isFile() && Utils::endsWith($name, CONTENT_EXT)) {
$page->init($file); $page->init($file);
@@ -465,8 +472,14 @@ class Pages
$this->grav->fireEvent('onFolderProcessed', new Event(['page' => $page])); $this->grav->fireEvent('onFolderProcessed', new Event(['page' => $page]));
} }
} }
} }
// Override the modified and ID so that it takes the latest change
// into account
$page->modified($last_modified);
$page->id($last_modified.md5($page->filePath()));
// Sort based on Defaults or Page Overridden sort order // Sort based on Defaults or Page Overridden sort order
$this->children[$page->path()] = $this->sort($page); $this->children[$page->path()] = $this->sort($page);