Skip to content

Commit

Permalink
Should address issue #38 where some people are not getting cache clears
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Aug 29, 2014
1 parent a737cfc commit 365f7bb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
5 changes: 3 additions & 2 deletions system/src/Grav/Common/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public function init(Grav $grav)
$this->key = substr(md5(($prefix ? $prefix : 'g') . $uri->rootUrl(true) . $this->config->key . GRAV_VERSION), 2, 8);

$this->driver = $this->getCacheDriver();

// Set the cache namespace to our unique key
$this->driver->setNamespace($this->key);
}

/**
Expand Down Expand Up @@ -132,7 +135,6 @@ public function getCacheDriver()
public function fetch($id)
{
if ($this->enabled) {
$id = $this->key . $id;
return $this->driver->fetch($id);
} else {
return false;
Expand All @@ -149,7 +151,6 @@ public function fetch($id)
public function save($id, $data, $lifetime = null)
{
if ($this->enabled) {
$id = $this->key . $id;
$this->driver->save($id, $data, $lifetime);
}
}
Expand Down
1 change: 0 additions & 1 deletion system/src/Grav/Common/Filesystem/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public static function lastModifiedFile($path)
}

}

return $last_modified;
}

Expand Down
2 changes: 1 addition & 1 deletion system/src/Grav/Common/Page/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function __construct($array = array())
public function init($file)
{
$this->filePath($file->getPathName());
$this->modified(filemtime($file->getPath()));
$this->modified($file->getMTime());
$this->id($this->modified().md5($this->filePath()));
$this->header();
$this->slug();
Expand Down
13 changes: 13 additions & 0 deletions system/src/Grav/Common/Page/Pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,17 @@ protected function recurse($directory = PAGES_DIR, Page &$parent = null)
throw new \RuntimeException('Fatal error when creating page instances.');
}

$last_modified = 0;

/** @var \DirectoryIterator $file */
foreach ($iterator as $file) {
$name = $file->getFilename();

$date = $file->getMTime();
if ($date > $last_modified) {
$last_modified = $date;
}

if ($file->isFile() && Utils::endsWith($name, CONTENT_EXT)) {

$page->init($file);
Expand Down Expand Up @@ -465,8 +472,14 @@ protected function recurse($directory = PAGES_DIR, Page &$parent = null)
$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
$this->children[$page->path()] = $this->sort($page);

Expand Down

0 comments on commit 365f7bb

Please sign in to comment.