mirror of
https://github.com/getgrav/grav.git
synced 2025-10-26 07:56:07 +01:00
Added method to check for changes by file rather than by folder, made it default option as its safest
This commit is contained in:
@@ -22,7 +22,7 @@ pages:
|
||||
cache:
|
||||
enabled: true # Set to true to enable caching
|
||||
check:
|
||||
pages: true # Check to see if page has been modifying to flush the cache
|
||||
method: page # Method to check for updates in pages: page|folder|none
|
||||
driver: auto # One of: auto|file|apc|xcache|memcache|memcached|wincache
|
||||
prefix: 'g' # Cache prefix string (prevents cache conflicts)
|
||||
|
||||
|
||||
@@ -15,13 +15,13 @@ abstract class Folder
|
||||
* @param string $path
|
||||
* @return int
|
||||
*/
|
||||
public static function lastModified($path)
|
||||
public static function lastModifiedFolder($path)
|
||||
{
|
||||
$last_modified = 0;
|
||||
|
||||
$directory = new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS);
|
||||
$iterator = new \RecursiveIteratorIterator($directory, \RecursiveIteratorIterator::SELF_FIRST);
|
||||
|
||||
$last_modified = 0;
|
||||
|
||||
/** @var \RecursiveDirectoryIterator $file */
|
||||
foreach ($iterator as $file) {
|
||||
$dir_modified = $file->getMTime();
|
||||
@@ -32,6 +32,35 @@ abstract class Folder
|
||||
return $last_modified;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively find the last modified time under given path by file.
|
||||
*
|
||||
* @param string $path
|
||||
* @return int
|
||||
*/
|
||||
public static function lastModifiedFile($path)
|
||||
{
|
||||
$last_modified = 0;
|
||||
|
||||
$dirItr = new \RecursiveDirectoryIterator($path);
|
||||
$filterItr = new GravRecursiveFilterIterator($dirItr);
|
||||
$itr = new \RecursiveIteratorIterator($filterItr, \RecursiveIteratorIterator::SELF_FIRST);
|
||||
|
||||
/** @var \RecursiveDirectoryIterator $file */
|
||||
foreach ($itr as $file) {
|
||||
|
||||
if (!$file->isDir()) {
|
||||
|
||||
$dir_modified = $file->getMTime();
|
||||
if ($dir_modified > $last_modified) {
|
||||
$last_modified = $dir_modified;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return recursive list of all files and directories under given path.
|
||||
*
|
||||
@@ -219,3 +248,19 @@ abstract class Folder
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class GravRecursiveFilterIterator extends \RecursiveFilterIterator {
|
||||
|
||||
public static $FILTERS = array(
|
||||
'.', '..', '.DS_Store'
|
||||
);
|
||||
|
||||
public function accept() {
|
||||
return !in_array(
|
||||
$this->current()->getFilename(),
|
||||
self::$FILTERS,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -356,8 +356,19 @@ class Pages
|
||||
$cache = $this->grav['cache'];
|
||||
/** @var Taxonomy $taxonomy */
|
||||
$taxonomy = $this->grav['taxonomy'];
|
||||
$last_modified = $config->get('system.cache.check.pages', true)
|
||||
? Folder::lastModified(PAGES_DIR) : 0;
|
||||
|
||||
// how should we check for last modified? Default is by page
|
||||
switch ($config->get('system.cache.check.method', 'page')) {
|
||||
case 'page':
|
||||
$last_modified = Folder::lastModifiedFile(PAGES_DIR);
|
||||
break;
|
||||
case 'folder':
|
||||
$last_modified = Folder::lastModifiedFolder(PAGES_DIR);
|
||||
break;
|
||||
default:
|
||||
$last_modified = 0;
|
||||
}
|
||||
|
||||
$page_cache_id = md5(USER_DIR.$last_modified);
|
||||
|
||||
list($this->instances, $this->routes, $this->children, $taxonomy_map, $this->sort) = $cache->fetch($page_cache_id);
|
||||
@@ -546,7 +557,7 @@ class Pages
|
||||
// else just sort the list according to specified key
|
||||
asort($list);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Move manually ordered items into the beginning of the list. Order of the unlisted items does not change.
|
||||
if (is_array($manual) && !empty($manual)) {
|
||||
|
||||
@@ -11,7 +11,7 @@ pages:
|
||||
cache:
|
||||
enabled: true
|
||||
check:
|
||||
pages: true
|
||||
method: page
|
||||
driver: auto
|
||||
prefix: 'g'
|
||||
|
||||
|
||||
5
user/pages/02.test/default.md
Normal file
5
user/pages/02.test/default.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
title: Test
|
||||
---
|
||||
|
||||
# Testing
|
||||
Reference in New Issue
Block a user