/**
* Constructor. Parameters are:
- * - server: A server info structure in the format required by each
+ * - server: A server info structure in the format required by each
* element in $wgDBServers.
*
- * - purgePeriod: The average number of object cache requests in between
- * garbage collection operations, where expired entries
- * are removed from the database. Or in other words, the
- * reciprocal of the probability of purging on any given
- * request. If this is set to zero, purging will never be
+ * - purgePeriod: The average number of object cache requests in between
+ * garbage collection operations, where expired entries
+ * are removed from the database. Or in other words, the
+ * reciprocal of the probability of purging on any given
+ * request. If this is set to zero, purging will never be
* done.
*
* - tableName: The table name to use, default is "objectcache".
*
- * - shards: The number of tables to use for data storage. If this is
- * more than 1, table names will be formed in the style
- * objectcacheNNN where NNN is the shard index, between 0 and
- * shards-1. The number of digits will be the minimum number
- * required to hold the largest shard index. Data will be
- * distributed across all tables by key hash. This is for
+ * - shards: The number of tables to use for data storage. If this is
+ * more than 1, table names will be formed in the style
+ * objectcacheNNN where NNN is the shard index, between 0 and
+ * shards-1. The number of digits will be the minimum number
+ * required to hold the largest shard index. Data will be
+ * distributed across all tables by key hash. This is for
* MySQL bugs 61735 and 61736.
*
* @param $params array
protected function getTableByShard( $index ) {
if ( $this->shards > 1 ) {
$decimals = strlen( $this->shards - 1 );
- return $this->tableName .
+ return $this->tableName .
sprintf( "%0{$decimals}d", $index );
} else {
return $this->tableName;
$db->begin();
// (bug 24425) use a replace if the db supports it instead of
// delete/insert to avoid clashes with conflicting keynames
- $db->replace(
- $this->getTableByKey( $key ),
+ $db->replace(
+ $this->getTableByKey( $key ),
array( 'keyname' ),
array(
'keyname' => $key,
try {
$db->begin();
- $db->delete(
- $this->getTableByKey( $key ),
- array( 'keyname' => $key ),
+ $db->delete(
+ $this->getTableByKey( $key ),
+ array( 'keyname' => $key ),
__METHOD__ );
$db->commit();
} catch ( DBQueryError $e ) {
try {
$db->begin();
- $row = $db->selectRow(
- $tableName,
+ $row = $db->selectRow(
+ $tableName,
array( 'value', 'exptime' ),
- array( 'keyname' => $key ),
- __METHOD__,
+ array( 'keyname' => $key ),
+ __METHOD__,
array( 'FOR UPDATE' ) );
if ( $row === false ) {
// Missing
'value' => $db->encodeBlob( $this->serialize( $newValue ) ),
'exptime' => $row->exptime
), __METHOD__, 'IGNORE' );
-
+
if ( $db->affectedRows() == 0 ) {
// Race condition. See bug 28611
$newValue = null;
$result = array();
for ( $i = 0; $i < $this->shards; $i++ ) {
- $res = $db->select( $this->getTableByShard( $i ),
+ $res = $db->select( $this->getTableByShard( $i ),
array( 'keyname' ), false, __METHOD__ );
foreach ( $res as $row ) {
$result[] = $row->keyname;
for ( $i = 0; $i < $this->shards; $i++ ) {
$db->begin();
$db->delete(
- $this->getTableByShard( $i ),
- array( 'exptime < ' . $db->addQuotes( $dbTimestamp ) ),
+ $this->getTableByShard( $i ),
+ array( 'exptime < ' . $db->addQuotes( $dbTimestamp ) ),
__METHOD__ );
$db->commit();
}