* @file
* @ingroup Cache
*/
+use MediaWiki\MediaWikiServices;
/**
* This class stores an arbitrary value along with its dependencies.
* @param CacheDependency|CacheDependency[] $deps A dependency or dependency
* array. All dependencies must be objects implementing CacheDependency.
*/
- function __construct( $value = false, $deps = array() ) {
+ function __construct( $value = false, $deps = [] ) {
$this->value = $value;
if ( !is_array( $deps ) ) {
- $deps = array( $deps );
+ $deps = [ $deps ];
}
$this->deps = $deps;
* callback was defined.
*/
static function getValueFromCache( $cache, $key, $expiry = 0, $callback = false,
- $callbackParams = array(), $deps = array()
+ $callbackParams = [], $deps = []
) {
$obj = $cache->get( $key );
function __sleep() {
$this->loadDependencyValues();
- return array( 'filename', 'timestamp' );
+ return [ 'filename', 'timestamp' ];
}
function loadDependencyValues() {
}
}
+/**
+ * @ingroup Cache
+ */
+class MainConfigDependency extends CacheDependency {
+ private $name;
+ private $value;
+
+ function __construct( $name ) {
+ $this->name = $name;
+ $this->value = $this->getConfig()->get( $this->name );
+ }
+
+ private function getConfig() {
+ return MediaWikiServices::getInstance()->getMainConfig();
+ }
+
+ /**
+ * @return bool
+ */
+ function isExpired() {
+ if ( !$this->getConfig()->has( $this->name ) ) {
+ return true;
+ }
+
+ return $this->getConfig()->get( $this->name ) != $this->value;
+ }
+}
+
/**
* @ingroup Cache
*/