diff --git a/system/config/system.yaml b/system/config/system.yaml index 6fd85e641..c99a173a3 100644 --- a/system/config/system.yaml +++ b/system/config/system.yaml @@ -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) diff --git a/system/src/Grav/Common/Filesystem/Folder.php b/system/src/Grav/Common/Filesystem/Folder.php index b71ce040a..0c1661a62 100644 --- a/system/src/Grav/Common/Filesystem/Folder.php +++ b/system/src/Grav/Common/Filesystem/Folder.php @@ -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 + ); + } + +} diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index 9dbcca008..0925d995d 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -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)) { diff --git a/user/config/system.yaml b/user/config/system.yaml index 1bf0c1516..43efc8222 100644 --- a/user/config/system.yaml +++ b/user/config/system.yaml @@ -11,7 +11,7 @@ pages: cache: enabled: true check: - pages: true + method: page driver: auto prefix: 'g' diff --git a/user/pages/02.test/default.md b/user/pages/02.test/default.md new file mode 100644 index 000000000..54cb70b34 --- /dev/null +++ b/user/pages/02.test/default.md @@ -0,0 +1,5 @@ +--- +title: Test +--- + +# Testing