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;
}
/**
$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" );
}
/**