* @return mixed Constructed instance
*/
public static function constructClassInstance( $clazz, $args ) {
+ // $args should be a non-associative array; show nice error if that's not the case
+ if ( $args && array_keys( $args ) !== range( 0, count( $args ) - 1 ) ) {
+ throw new InvalidArgumentException( __METHOD__ . ': $args cannot be an associative array' );
+ }
+
// TODO: when PHP min version supported is >=5.6.0 replace this
- // function body with `return new $clazz( ... $args );`.
+ // with `return new $clazz( ... $args );`.
$obj = null;
switch ( count( $args ) ) {
case 0:
const TSE_NONE = -1;
/** Max TTL to store keys when a data sourced is lagged */
const TTL_LAGGED = 30;
+ /** Idiom for delete() for "no hold-off" */
+ const HOLDOFF_NONE = 0;
/** Tiny negative float to use when CTL comes up >= 0 due to clock skew */
const TINY_NEGATIVE = -0.000001;
$checkKeyTimesForAll = $this->processCheckKeys( $checksForAll, $wrappedValues, $now );
$checkKeyTimesByKey = array();
foreach ( $checksByKey as $cacheKey => $checks ) {
- $checkKeyTimesByKey[$cacheKey] = $this->processCheckKeys( $checks, $wrappedValues, $now );
+ $checkKeyTimesByKey[$cacheKey] =
+ $this->processCheckKeys( $checks, $wrappedValues, $now );
}
// Get the main cache value for each key and validate them
*
* The $ttl parameter can be used when purging values that have not actually changed
* recently. For example, a cleanup script to purge cache entries does not really need
- * a hold-off period, so it can use the value 1. Likewise for user-requested purge.
+ * a hold-off period, so it can use HOLDOFF_NONE. Likewise for user-requested purge.
* Note that $ttl limits the effective range of 'lockTSE' for getWithSetCallback().
*
* If called twice on the same key, then the last hold-off TTL takes precedence. For
*/
final public function delete( $key, $ttl = self::HOLDOFF_TTL ) {
$key = self::VALUE_KEY_PREFIX . $key;
- // Avoid indefinite key salting for sanity
- $ttl = max( $ttl, 1 );
- // Update the local datacenter immediately
- $ok = $this->cache->set( $key, self::PURGE_VAL_PREFIX . microtime( true ), $ttl );
- // Publish the purge to all datacenters
- return $this->relayPurge( $key, $ttl ) && $ok;
+
+ if ( $ttl <= 0 ) {
+ // Update the local datacenter immediately
+ $ok = $this->cache->delete( $key );
+ // Publish the purge to all datacenters
+ $ok = $this->relayDelete( $key ) && $ok;
+ } else {
+ // Update the local datacenter immediately
+ $ok = $this->cache->set( $key, self::PURGE_VAL_PREFIX . microtime( true ), $ttl );
+ // Publish the purge to all datacenters
+ $ok = $this->relayPurge( $key, $ttl ) && $ok;
+ }
+
+ return $ok;
}
/**
+/*
+ * Local backports:
+ *
+ * - 4fbbc737c86b500c11bbb471ec1001c50ab8853c
+ * SelectFileWidget: Use i18n string for button label
+ * We totally forgot to use a localisation message we carefully introduced.
+ */
+
/*!
* OOjs UI v0.13.3
* https://www.mediawiki.org/wiki/OOjs_UI
this.selectButton = new OO.ui.ButtonWidget( {
classes: [ 'oo-ui-selectFileWidget-selectButton' ],
- label: 'Select a file',
+ label: OO.ui.msg( 'ooui-selectfile-button-select' ),
disabled: this.disabled || !this.isSupported
} );
'11 args' => array( array( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ) ),
);
}
+
+ /**
+ * @expectedException InvalidArgumentException
+ */
+ public function testNamedArgs() {
+ $args = array( 'foo' => 1, 'bar' => 2, 'baz' => 3 );
+ $obj = ObjectFactory::constructClassInstance(
+ 'ObjectFactoryTestFixture', $args
+ );
+ }
}
class ObjectFactoryTestFixture {
$this->assertLessThan( 0, $curTTL, "Deleted key has current TTL < 0" );
$this->cache->set( $key, $value . 'more' );
+ $v = $this->cache->get( $key, $curTTL );
$this->assertFalse( $v, "Deleted key is tombstoned and has false value" );
$this->assertLessThan( 0, $curTTL, "Deleted key is tombstoned and has current TTL < 0" );
+
+ $this->cache->set( $key, $value );
+ $this->cache->delete( $key, WANObjectCache::HOLDOFF_NONE );
+
+ $curTTL = null;
+ $v = $this->cache->get( $key, $curTTL );
+ $this->assertFalse( $v, "Deleted key has false value" );
+ $this->assertNull( $curTTL, "Deleted key has null current TTL" );
+
+ $this->cache->set( $key, $value );
+ $v = $this->cache->get( $key, $curTTL );
+ $this->assertEquals( $value, $v, "Key was created with value" );
+ $this->assertGreaterThan( 0, $curTTL, "Existing key has current TTL > 0" );
}
/**