diff --git a/CHANGELOG.md b/CHANGELOG.md index c35fd6b33..4565f9f0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# v1.7.33 +## mm/dd/2022 + +1. [](#bugfix) + * Fixed missing changes in yaml & markdown files if saved multiple times during the same second because of a caching issue + # v1.7.32 ## 03/28/2022 diff --git a/system/src/Grav/Common/File/CompiledFile.php b/system/src/Grav/Common/File/CompiledFile.php index 222842278..ce133a600 100644 --- a/system/src/Grav/Common/File/CompiledFile.php +++ b/system/src/Grav/Common/File/CompiledFile.php @@ -32,9 +32,10 @@ trait CompiledFile public function content($var = null) { try { + $filename = $this->filename; // If nothing has been loaded, attempt to get pre-compiled version of the file first. if ($var === null && $this->raw === null && $this->content === null) { - $key = md5($this->filename); + $key = md5($filename); $file = PhpFile::instance(CACHE_DIR . "compiled/files/{$key}{$this->extension}.php"); $modified = $this->modified(); @@ -48,13 +49,15 @@ trait CompiledFile $class = get_class($this); + $size = filesize($filename); $cache = $file->exists() ? $file->content() : null; // Load real file if cache isn't up to date (or is invalid). if (!isset($cache['@class']) || $cache['@class'] !== $class || $cache['modified'] !== $modified - || $cache['filename'] !== $this->filename + || ($cache['size'] ?? null) !== $size + || $cache['filename'] !== $filename ) { // Attempt to lock the file for writing. try { @@ -67,8 +70,9 @@ trait CompiledFile $data = (array)$this->decode($this->raw()); $cache = [ '@class' => $class, - 'filename' => $this->filename, + 'filename' => $filename, 'modified' => $modified, + 'size' => $size, 'data' => $data ]; @@ -89,7 +93,7 @@ trait CompiledFile $this->content = $cache['data']; } } catch (Exception $e) { - throw new RuntimeException(sprintf('Failed to read %s: %s', Utils::basename($this->filename), $e->getMessage()), 500, $e); + throw new RuntimeException(sprintf('Failed to read %s: %s', Utils::basename($filename), $e->getMessage()), 500, $e); } return parent::content($var);