MediaWiki  1.23.2
BagOStuff Class Reference

interface is intended to be more or less compatible with the PHP memcached client. More...

Inheritance diagram for BagOStuff:

Public Member Functions

 add ( $key, $value, $exptime=0)
 
 cas ( $casToken, $key, $value, $exptime=0)
 Check and set an item. More...
 
 clearLastError ()
 Clear the "last error" registry. More...
 
 debug ( $text)
 
 decr ( $key, $value=1)
 Decrease stored value of $key by $value while preserving its TTL. More...
 
 delete ( $key, $time=0)
 Delete an item. More...
 
 deleteObjectsExpiringBefore ( $date, $progressCallback=false)
 Delete all objects expiring before a certain date. More...
 
 get ( $key, &$casToken=null)
 Get an item with the given key. More...
 
 getLastError ()
 Get the "last error" registered; clearLastError() should be called manually. More...
 
 getMulti (array $keys)
 Get an associative array containing the item for each of the keys that have items. More...
 
 incr ( $key, $value=1)
 Increase stored value of $key by $value while preserving its TTL. More...
 
 lock ( $key, $timeout=6)
 
 merge ( $key, closure $callback, $exptime=0, $attempts=10)
 Merge changes into the existing cache value (possibly creating a new one). More...
 
 replace ( $key, $value, $exptime=0)
 
 set ( $key, $value, $exptime=0)
 Set an item. More...
 
 setDebug ( $bool)
 
 unlock ( $key)
 

Public Attributes

const ERR_NO_RESPONSE = 1
 
const ERR_NONE = 0
 Possible values for getLastError() More...
 
const ERR_UNEXPECTED = 3
 
const ERR_UNREACHABLE = 2
 

Protected Member Functions

 convertExpiry ( $exptime)
 Convert an optionally relative time to an absolute time. More...
 
 convertToRelative ( $exptime)
 Convert an optionally absolute expiry time to a relative time. More...
 
 isInteger ( $value)
 Check if a value is an integer. More...
 
 mergeViaCas ( $key, closure $callback, $exptime=0, $attempts=10)
 
 mergeViaLock ( $key, closure $callback, $exptime=0, $attempts=10)
 
 setLastError ( $err)
 Set the "last error" registry. More...
 

Protected Attributes

 $lastError = self::ERR_NONE
 

Private Attributes

 $debugMode = false
 

Detailed Description

interface is intended to be more or less compatible with the PHP memcached client.

backends for local hash array and SQL table included: $bag = new HashBagOStuff(); $bag = new SqlBagOStuff(); # connect to db first

Definition at line 43 of file BagOStuff.php.

Member Function Documentation

◆ add()

BagOStuff::add (   $key,
  $value,
  $exptime = 0 
)
Parameters
$keystring
$valuemixed
$exptimeinteger
Returns
bool success

Reimplemented in MemcachedPeclBagOStuff, MultiWriteBagOStuff, MemcachedBagOStuff, and RedisBagOStuff.

Definition at line 256 of file BagOStuff.php.

References $value.

Referenced by lock(), and mergeViaCas().

◆ cas()

BagOStuff::cas (   $casToken,
  $key,
  $value,
  $exptime = 0 
)
abstract

Check and set an item.

Parameters
$casTokenmixed
$keystring
$valuemixed
int$exptimeEither an interval in seconds or a unix timestamp for expiry
Returns
bool success

Reimplemented in SqlBagOStuff, MemcachedPeclBagOStuff, HashBagOStuff, MemcachedBagOStuff, MultiWriteBagOStuff, XCacheBagOStuff, WinCacheBagOStuff, APCBagOStuff, RedisBagOStuff, and EmptyBagOStuff.

Referenced by mergeViaCas().

◆ clearLastError()

BagOStuff::clearLastError ( )

Clear the "last error" registry.

Since
1.23

Reimplemented in MultiWriteBagOStuff.

Definition at line 323 of file BagOStuff.php.

References ERR_NONE.

Referenced by lock().

◆ convertExpiry()

BagOStuff::convertExpiry (   $exptime)
protected

Convert an optionally relative time to an absolute time.

Parameters
$exptimeinteger
Returns
int

Definition at line 351 of file BagOStuff.php.

Referenced by HashBagOStuff\set().

◆ convertToRelative()

BagOStuff::convertToRelative (   $exptime)
protected

Convert an optionally absolute expiry time to a relative time.

If an absolute time is specified which is in the past, use a short expiry time.

Parameters
$exptimeinteger
Returns
integer

Definition at line 366 of file BagOStuff.php.

Referenced by RedisBagOStuff\add(), RedisBagOStuff\cas(), and RedisBagOStuff\set().

◆ debug()

BagOStuff::debug (   $text)
Parameters
$textstring

Definition at line 339 of file BagOStuff.php.

References wfDebug().

Referenced by RedisBagOStuff\getMulti(), SqlBagOStuff\getMulti(), and RedisBagOStuff\logRequest().

◆ decr()

BagOStuff::decr (   $key,
  $value = 1 
)

Decrease stored value of $key by $value while preserving its TTL.

Parameters
$keyString
$valueInteger
Returns
integer

Reimplemented in MemcachedPeclBagOStuff, MultiWriteBagOStuff, XCacheBagOStuff, APCBagOStuff, and MemcachedPhpBagOStuff.

Definition at line 306 of file BagOStuff.php.

References $value, and incr().

◆ delete()

BagOStuff::delete (   $key,
  $time = 0 
)
abstract

Delete an item.

Parameters
$keystring
int$timeAmount of time to delay the operation (mostly memcached-specific)
Returns
bool True if the item was deleted or not found, false on failure

Reimplemented in SqlBagOStuff, MemcachedPeclBagOStuff, RedisBagOStuff, HashBagOStuff, MultiWriteBagOStuff, MemcachedBagOStuff, XCacheBagOStuff, WinCacheBagOStuff, APCBagOStuff, and EmptyBagOStuff.

◆ deleteObjectsExpiringBefore()

BagOStuff::deleteObjectsExpiringBefore (   $date,
  $progressCallback = false 
)

Delete all objects expiring before a certain date.

Parameters
string$dateThe reference date in MW format
$progressCallbackcallback|bool Optional, a function which will be called regularly during long-running operations with the percentage progress as the first parameter.
Returns
bool on success, false if unimplemented

Reimplemented in SqlBagOStuff, and MultiWriteBagOStuff.

Definition at line 227 of file BagOStuff.php.

◆ get()

BagOStuff::get (   $key,
$casToken = null 
)
abstract

Get an item with the given key.

Returns false if it does not exist.

Parameters
$keystring
$casToken[optional]mixed
Returns
mixed Returns false on failure

Reimplemented in SqlBagOStuff, MemcachedPeclBagOStuff, RedisBagOStuff, MultiWriteBagOStuff, MemcachedBagOStuff, HashBagOStuff, WinCacheBagOStuff, XCacheBagOStuff, EmptyBagOStuff, and APCBagOStuff.

Referenced by JobQueueDB\doDeduplicateRootJob().

◆ getLastError()

BagOStuff::getLastError ( )

Get the "last error" registered; clearLastError() should be called manually.

Returns
integer ERR_* constant for the "last error" registry
Since
1.23

Reimplemented in MultiWriteBagOStuff.

Definition at line 315 of file BagOStuff.php.

References $lastError.

Referenced by lock().

◆ getMulti()

BagOStuff::getMulti ( array  $keys)

Get an associative array containing the item for each of the keys that have items.

Parameters
array$keysList of strings
Returns
Array

Reimplemented in MemcachedPeclBagOStuff, SqlBagOStuff, RedisBagOStuff, and MemcachedPhpBagOStuff.

Definition at line 239 of file BagOStuff.php.

References $keys, $res, array(), and as.

◆ incr()

BagOStuff::incr (   $key,
  $value = 1 
)

Increase stored value of $key by $value while preserving its TTL.

Parameters
string$keyKey to increase
$valueInteger: Value to add to $key (Default 1)
Returns
integer|bool New value or false on failure

Reimplemented in RedisBagOStuff, MemcachedPeclBagOStuff, MultiWriteBagOStuff, XCacheBagOStuff, APCBagOStuff, MemcachedPhpBagOStuff, and SqlBagOStuff.

Definition at line 284 of file BagOStuff.php.

References $n, $value, isInteger(), lock(), and unlock().

Referenced by decr().

◆ isInteger()

BagOStuff::isInteger (   $value)
protected

Check if a value is an integer.

Parameters
$valuemixed
Returns
bool

Definition at line 384 of file BagOStuff.php.

References $value.

Referenced by APCBagOStuff\get(), XCacheBagOStuff\get(), incr(), APCBagOStuff\set(), and XCacheBagOStuff\set().

◆ lock()

BagOStuff::lock (   $key,
  $timeout = 6 
)
Parameters
$keystring
$timeoutinteger [optional]
Returns
bool success

Reimplemented in MultiWriteBagOStuff, and MemcachedPhpBagOStuff.

Definition at line 179 of file BagOStuff.php.

References $sleep, $timestamp, add(), clearLastError(), and getLastError().

Referenced by incr(), and mergeViaLock().

◆ merge()

BagOStuff::merge (   $key,
closure  $callback,
  $exptime = 0,
  $attempts = 10 
)

Merge changes into the existing cache value (possibly creating a new one).

The callback function returns the new value given the current value (possibly false), and takes the arguments: (this BagOStuff object, cache key, current value).

Parameters
$keystring
$callbackclosure Callback method to be executed
int$exptimeEither an interval in seconds or a unix timestamp for expiry
int$attemptsThe amount of times to attempt a merge in case of failure
Returns
bool success

Reimplemented in MultiWriteBagOStuff, XCacheBagOStuff, APCBagOStuff, and EmptyBagOStuff.

Definition at line 110 of file BagOStuff.php.

References mergeViaCas().

◆ mergeViaCas()

BagOStuff::mergeViaCas (   $key,
closure  $callback,
  $exptime = 0,
  $attempts = 10 
)
protected
See also
BagOStuff::merge()
Parameters
$keystring
$callbackclosure Callback method to be executed
int$exptimeEither an interval in seconds or a unix timestamp for expiry
int$attemptsThe amount of times to attempt a merge in case of failure
Returns
bool success

Definition at line 123 of file BagOStuff.php.

References $success, $value, add(), and cas().

Referenced by merge().

◆ mergeViaLock()

BagOStuff::mergeViaLock (   $key,
closure  $callback,
  $exptime = 0,
  $attempts = 10 
)
protected
See also
BagOStuff::merge()
Parameters
$keystring
$callbackclosure Callback method to be executed
int$exptimeEither an interval in seconds or a unix timestamp for expiry
int$attemptsThe amount of times to attempt a merge in case of failure
Returns
bool success

Definition at line 152 of file BagOStuff.php.

References $success, $value, lock(), and unlock().

Referenced by APCBagOStuff\merge(), and XCacheBagOStuff\merge().

◆ replace()

BagOStuff::replace (   $key,
  $value,
  $exptime = 0 
)
Parameters
$keystring
$valuemixed
$exptimeint
Returns
bool success
Deprecated:
1.23

Reimplemented in MultiWriteBagOStuff.

Definition at line 270 of file BagOStuff.php.

References $value, and wfDeprecated().

◆ set()

BagOStuff::set (   $key,
  $value,
  $exptime = 0 
)
abstract

Set an item.

Parameters
$keystring
$valuemixed
int$exptimeEither an interval in seconds or a unix timestamp for expiry
Returns
bool success

Reimplemented in SqlBagOStuff, MemcachedPeclBagOStuff, MultiWriteBagOStuff, HashBagOStuff, MemcachedBagOStuff, APCBagOStuff, RedisBagOStuff, XCacheBagOStuff, WinCacheBagOStuff, and EmptyBagOStuff.

Referenced by JobQueueDB\doDeduplicateRootJob().

◆ setDebug()

BagOStuff::setDebug (   $bool)
Parameters
$boolbool

Reimplemented in MultiWriteBagOStuff, and MemcachedPhpBagOStuff.

Definition at line 57 of file BagOStuff.php.

◆ setLastError()

BagOStuff::setLastError (   $err)
protected

Set the "last error" registry.

Parameters
$errinteger ERR_* constant
Since
1.23

Definition at line 332 of file BagOStuff.php.

Referenced by MemcachedPeclBagOStuff\checkResult(), RedisBagOStuff\getConnection(), RedisBagOStuff\handleException(), SqlBagOStuff\handleReadError(), and SqlBagOStuff\handleWriteError().

◆ unlock()

BagOStuff::unlock (   $key)
Parameters
$keystring
Returns
bool success

Reimplemented in MultiWriteBagOStuff, and MemcachedPhpBagOStuff.

Definition at line 214 of file BagOStuff.php.

Referenced by incr(), and mergeViaLock().

Member Data Documentation

◆ $debugMode

BagOStuff::$debugMode = false
private

Definition at line 44 of file BagOStuff.php.

◆ $lastError

BagOStuff::$lastError = self::ERR_NONE
protected

Definition at line 46 of file BagOStuff.php.

Referenced by getLastError().

◆ ERR_NO_RESPONSE

const BagOStuff::ERR_NO_RESPONSE = 1

Definition at line 50 of file BagOStuff.php.

◆ ERR_NONE

const BagOStuff::ERR_NONE = 0

Possible values for getLastError()

Definition at line 49 of file BagOStuff.php.

Referenced by clearLastError(), and MultiWriteBagOStuff\getLastError().

◆ ERR_UNEXPECTED

◆ ERR_UNREACHABLE

const BagOStuff::ERR_UNREACHABLE = 2

The documentation for this class was generated from the following file: