openrat-cms

# OpenRat Content Management System
git clone http://git.code.weiherhei.de/openrat-cms.git
Log | Files | Refs

commit 81746b6ffb72bac071577c75238539f159a77422
parent b6f61e1aa404a75a5a022392bc20836ce94e830f
Author: Jan Dankert <develop@jandankert.de>
Date:   Sat, 18 May 2019 22:27:04 +0200

New: Filecache mit Ablauf-Zeitpunkt.

Diffstat:
modules/cms-core/model/File.class.php | 2+-
modules/cms-core/model/Page.class.php | 2+-
modules/cms-core/model/Value.class.php | 2+-
modules/util/cache/FileCache.class.php | 14++++++++++++--
4 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/modules/cms-core/model/File.class.php b/modules/cms-core/model/File.class.php @@ -93,7 +93,7 @@ class File extends BaseObject return new FileCache( $cacheKey,function() { return $this->loadValueFromDatabase(); - } ); + }, $this->lastchangeDate ); } /** diff --git a/modules/cms-core/model/Page.class.php b/modules/cms-core/model/Page.class.php @@ -105,7 +105,7 @@ class Page extends BaseObject return new FileCache( $cacheKey,function() { return $this->generateValue(); - } ); + }, $this->lastchangeDate ); } diff --git a/modules/cms-core/model/Value.class.php b/modules/cms-core/model/Value.class.php @@ -565,7 +565,7 @@ SQL 'publish'=>\ClassUtils::getSimpleClassName($this->publisher) ); return new FileCache( $cacheKey,function() { return $this->generateValue(); - } ); + },$this->lastchangeTimeStamp ); } /** diff --git a/modules/util/cache/FileCache.class.php b/modules/util/cache/FileCache.class.php @@ -28,7 +28,7 @@ class FileCache * @param $key array Cache-Key * @param $loader Callable */ - public function __construct( $key, $loader ) + public function __construct( $key, $loader, $lastModified = 0 ) { $filename = FileUtils::getTempDir() . '/'. 'openrat-cache'; @@ -42,6 +42,15 @@ class FileCache $this->filename = $filename; $this->loader = $loader; + + $this->invalidateIfOlderThan( $lastModified ); + } + + + public function invalidateIfOlderThan($lastModified) { + + if ( is_file($this->filename) && filemtime($this->filename) < $lastModified ) + $this->invalidate(); } @@ -51,7 +60,8 @@ class FileCache public function invalidate() { if ( is_file($this->filename)) - unlink( $this->filename); + // Should use '@' here to deny race conditions, where another request is calling this method. + @unlink( $this->filename); }