MediaWiki  REL1_24
BagOStuff Class Reference

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

Inheritance diagram for BagOStuff:

List of all members.

Public Member Functions

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

Public Attributes

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

Protected Member Functions

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

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

BagOStuff::add ( key,
value,
exptime = 0 
)
Parameters:
string$key
mixed$value
int$exptime
Returns:
bool Success

Reimplemented in RedisBagOStuff, MemcachedPeclBagOStuff, MultiWriteBagOStuff, and MemcachedBagOStuff.

Definition at line 273 of file BagOStuff.php.

References $key, and $value.

Referenced by incrWithInit(), lock(), and mergeViaCas().

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

Check and set an item.

Parameters:
mixed$casToken
string$key
mixed$value
int$exptimeEither an interval in seconds or a unix timestamp for expiry
Returns:
bool Success

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

Referenced by mergeViaCas().

Clear the "last error" registry.

Since:
1.23

Reimplemented in MultiWriteBagOStuff.

Definition at line 342 of file BagOStuff.php.

References ERR_NONE.

Referenced by lock().

BagOStuff::convertExpiry ( exptime) [protected]

Convert an optionally relative time to an absolute time.

Parameters:
int$exptime
Returns:
int

Definition at line 370 of file BagOStuff.php.

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:
int$exptime
Returns:
int

Definition at line 385 of file BagOStuff.php.

Referenced by RedisBagOStuff\add().

BagOStuff::debug ( text)
Parameters:
string$text

Definition at line 358 of file BagOStuff.php.

References wfDebug().

BagOStuff::decr ( key,
value = 1 
)

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

Parameters:
string$key
int$value
Returns:
int

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

Definition at line 308 of file BagOStuff.php.

References $key, $value, and incr().

BagOStuff::delete ( key,
time = 0 
) [abstract]

Delete an item.

Parameters:
string$key
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.

BagOStuff::deleteObjectsExpiringBefore ( date,
progressCallback = false 
)

Delete all objects expiring before a certain date.

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

Reimplemented in SqlBagOStuff, and MultiWriteBagOStuff.

Definition at line 227 of file BagOStuff.php.

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

Get an item with the given key.

Returns false if it does not exist.

Parameters:
string$key
mixed$casToken[optional]
Returns:
mixed Returns false on failure

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

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

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

Reimplemented in MultiWriteBagOStuff.

Definition at line 334 of file BagOStuff.php.

Referenced by lock().

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 $key, $res, array(), and as.

BagOStuff::incr ( key,
value = 1 
)

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

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

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

Definition at line 286 of file BagOStuff.php.

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

Referenced by decr(), and incrWithInit().

BagOStuff::incrWithInit ( key,
ttl,
value = 1,
init = 1 
)

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

This will create the key with value $init and TTL $ttl if not present

Parameters:
string$key
int$ttl
int$value
int$init
Returns:
bool
Since:
1.24

Definition at line 324 of file BagOStuff.php.

References $key, $value, add(), and incr().

BagOStuff::isInteger ( value) [protected]

Check if a value is an integer.

Parameters:
mixed$value
Returns:
bool

Definition at line 403 of file BagOStuff.php.

References $value.

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

BagOStuff::lock ( key,
timeout = 6 
)
Parameters:
string$key
int$timeout[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().

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:
string$key
Closure$callbackCallback 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 $key, and mergeViaCas().

BagOStuff::mergeViaCas ( key,
Closure $  callback,
exptime = 0,
attempts = 10 
) [protected]
See also:
BagOStuff::merge()
Parameters:
string$key
Closure$callbackCallback 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 $key, $success, $value, add(), and cas().

Referenced by merge().

BagOStuff::mergeViaLock ( key,
Closure $  callback,
exptime = 0,
attempts = 10 
) [protected]
See also:
BagOStuff::merge()
Parameters:
string$key
Closure$callbackCallback 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 $key, $success, $value, lock(), and unlock().

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

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

Set an item.

Parameters:
string$key
mixed$value
int$exptimeEither an interval in seconds or a unix timestamp for expiry
Returns:
bool Success

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

BagOStuff::setDebug ( bool)
Parameters:
bool$bool

Reimplemented in MultiWriteBagOStuff, and MemcachedPhpBagOStuff.

Definition at line 57 of file BagOStuff.php.

BagOStuff::setLastError ( err) [protected]

Set the "last error" registry.

Parameters:
int$errERR_* constant
Since:
1.23

Definition at line 351 of file BagOStuff.php.

Referenced by MemcachedPeclBagOStuff\checkResult().

BagOStuff::setMulti ( array data,
exptime = 0 
)

Batch insertion.

Parameters:
array$data$key => $value assoc array
int$exptimeEither an interval in seconds or a unix timestamp for expiry
Returns:
bool Success
Since:
1.24

Reimplemented in SqlBagOStuff, MemcachedPeclBagOStuff, and RedisBagOStuff.

Definition at line 257 of file BagOStuff.php.

References $key, $res, $value, and as.

BagOStuff::unlock ( key)
Parameters:
string$key
Returns:
bool Success

Reimplemented in MultiWriteBagOStuff, and MemcachedPhpBagOStuff.

Definition at line 214 of file BagOStuff.php.

Referenced by incr(), and mergeViaLock().


Member Data Documentation

BagOStuff::$debugMode = false [private]

Definition at line 44 of file BagOStuff.php.

BagOStuff::$lastError = self::ERR_NONE [protected]

Definition at line 46 of file BagOStuff.php.

Definition at line 50 of file BagOStuff.php.

Possible values for getLastError()

Definition at line 49 of file BagOStuff.php.

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

Definition at line 52 of file BagOStuff.php.

Referenced by MemcachedPeclBagOStuff\checkResult().

Definition at line 51 of file BagOStuff.php.


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