3 * Data caching with dependencies.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
27 class FileDependency
extends CacheDependency
{
32 * Create a file dependency
34 * @param string $filename The name of the file, preferably fully qualified
35 * @param null|bool|int $timestamp The unix last modified timestamp, or false if the
36 * file does not exist. If omitted, the timestamp will be loaded from
39 * A dependency on a nonexistent file will be triggered when the file is
40 * created. A dependency on an existing file will be triggered when the
43 function __construct( $filename, $timestamp = null ) {
44 $this->filename
= $filename;
45 $this->timestamp
= $timestamp;
52 $this->loadDependencyValues();
54 return [ 'filename', 'timestamp' ];
57 function loadDependencyValues() {
58 if ( is_null( $this->timestamp
) ) {
59 Wikimedia\
suppressWarnings();
60 # Dependency on a non-existent file stores "false"
61 # This is a valid concept!
62 $this->timestamp
= filemtime( $this->filename
);
63 Wikimedia\restoreWarnings
();
70 function isExpired() {
71 Wikimedia\
suppressWarnings();
72 $lastmod = filemtime( $this->filename
);
73 Wikimedia\restoreWarnings
();
74 if ( $lastmod === false ) {
75 if ( $this->timestamp
=== false ) {
80 wfDebug( "Dependency triggered: {$this->filename} deleted.\n" );
85 if ( $lastmod > $this->timestamp
) {
87 wfDebug( "Dependency triggered: {$this->filename} changed.\n" );