MediaWiki  REL1_22
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.
 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.
 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.
 lock ($key, $timeout=60)
 merge ($key, closure $callback, $exptime=0, $attempts=10)
 Merge changes into the existing cache value (possibly creating a new one).
 replace ($key, $value, $exptime=0)
 set ($key, $value, $exptime=0)
 Set an item.
 setDebug ($bool)
 unlock ($key)

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)

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:
$keystring
$valuemixed
$exptimeinteger
Returns:
bool success

Reimplemented in DBABagOStuff, RedisBagOStuff, MemcachedPeclBagOStuff, MultiWriteBagOStuff, and MemcachedBagOStuff.

Definition at line 241 of file BagOStuff.php.

References $key, and $value.

Referenced by lock(), and mergeViaCas().

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, DBABagOStuff, EhcacheBagOStuff, MemcachedPeclBagOStuff, RedisBagOStuff, HashBagOStuff, MemcachedBagOStuff, MultiWriteBagOStuff, XCacheBagOStuff, WinCacheBagOStuff, APCBagOStuff, and EmptyBagOStuff.

Referenced by mergeViaCas().

BagOStuff::convertExpiry ( exptime) [protected]

Convert an optionally relative time to an absolute time.

Parameters:
$exptimeinteger
Returns:
int

Definition at line 308 of file BagOStuff.php.

Referenced by DBABagOStuff\encode(), HashBagOStuff\set(), and EhcacheBagOStuff\set().

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 323 of file BagOStuff.php.

BagOStuff::debug ( text)
Parameters:
$textstring

Definition at line 296 of file BagOStuff.php.

References wfDebug().

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 289 of file BagOStuff.php.

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

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, DBABagOStuff, EhcacheBagOStuff, 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
$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 212 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:
$keystring
$casToken[optional]mixed
Returns:
mixed Returns false on failure

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

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 224 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
$valueInteger: Value to add to $key (Default 1)
Returns:
integer|bool New value or false on failure

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

Definition at line 267 of file BagOStuff.php.

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

Referenced by decr().

BagOStuff::isInteger ( value) [protected]

Check if a value is an integer.

Parameters:
$valuemixed
Returns:
bool

Definition at line 341 of file BagOStuff.php.

References $value.

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

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

Reimplemented in MultiWriteBagOStuff, and MemcachedPhpBagOStuff.

Definition at line 171 of file BagOStuff.php.

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

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:
$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 EhcacheBagOStuff, MultiWriteBagOStuff, XCacheBagOStuff, APCBagOStuff, and EmptyBagOStuff.

Definition at line 102 of file BagOStuff.php.

References $key, and 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 115 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:
$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 144 of file BagOStuff.php.

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

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

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

Reimplemented in RedisBagOStuff, MemcachedPeclBagOStuff, MultiWriteBagOStuff, and MemcachedBagOStuff.

Definition at line 254 of file BagOStuff.php.

References $key, and $value.

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, DBABagOStuff, MemcachedPeclBagOStuff, EhcacheBagOStuff, MultiWriteBagOStuff, RedisBagOStuff, HashBagOStuff, MemcachedBagOStuff, XCacheBagOStuff, WinCacheBagOStuff, APCBagOStuff, and EmptyBagOStuff.

BagOStuff::setDebug ( bool)
Parameters:
$boolbool

Reimplemented in MultiWriteBagOStuff, and MemcachedPhpBagOStuff.

Definition at line 49 of file BagOStuff.php.

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

Reimplemented in MultiWriteBagOStuff, and MemcachedPhpBagOStuff.

Definition at line 199 of file BagOStuff.php.

Referenced by incr(), and mergeViaLock().


Member Data Documentation

BagOStuff::$debugMode = false [private]

Definition at line 44 of file BagOStuff.php.


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