\Horde_Memcache

This class provides an API or Horde code to interact with a centrally configured memcache installation.

memcached website: http://www.danga.com/memcached/

Summary

Methods
Properties
Constants
__construct()
_init()
shutdown()
delete()
get()
set()
replace()
lock()
unlock()
flush()
stats()
failover()
serialize()
unserialize()
No public properties found
FLAGS_RESERVED
LOCK_TIMEOUT
LOCK_SUFFIX
MAX_SIZE
VERSION
_set()
_lockAdd()
_key()
_getOSKeyArray()
_getFlags()
$_locks
$_logger
$_memcache
$_noexist
$_params
$_servers
N/A
No private methods found
No private properties found
N/A

Constants

FLAGS_RESERVED

FLAGS_RESERVED

The number of bits reserved by PHP's memcache layer for internal flag use.

LOCK_TIMEOUT

LOCK_TIMEOUT

Locking timeout.

LOCK_SUFFIX

LOCK_SUFFIX

Suffix added to key to create the lock entry.

MAX_SIZE

MAX_SIZE

The max storage size of the memcache server. This should be slightly smaller than the actual value due to overhead. By default, the max slab size of memcached (as of 1.1.2) is 1 MB.

VERSION

VERSION

Serializable version.

Properties

$_locks

$_locks : array

Locked keys.

Type

array

$_logger

$_logger : \Horde_Log_Logger

Logger instance.

Type

\Horde_Log_Logger

$_memcache

$_memcache : \Memcache

Memcache object.

Type

\Memcache

$_noexist

$_noexist : array

A list of items known not to exist.

Type

array

$_params

$_params : array

Memcache defaults.

Type

array

$_servers

$_servers : array

The list of active servers.

Type

array

Methods

__construct()

__construct(array  $params = array()) 

Constructor.

Parameters

array $params

Configuration parameters:

  • compression: (boolean) Compress data inside memcache? DEFAULT: false
  • c_threshold: (integer) The minimum value length before attempting to compress. DEFAULT: none
  • hostspec: (array) The memcached host(s) to connect to. DEFAULT: 'localhost'
  • large_items: (boolean) Allow storing large data items (larger than Horde_Memcache::MAX_SIZE)? Currently not supported with memcached extension. DEFAULT: true
  • persistent: (boolean) Use persistent DB connections? DEFAULT: false
  • prefix: (string) The prefix to use for the memcache keys. DEFAULT: 'horde'
  • port: (array) The port(s) memcache is listening on. Leave empty if using UNIX sockets. DEFAULT: 11211
  • weight: (array) The weight(s) to use for each memcached host. DEFAULT: none (equal weight to all servers)

Throws

\Horde_Memcache_Exception

_init()

_init() 

Do initialization.

Throws

\Horde_Memcache_Exception

shutdown()

shutdown() 

Shutdown function.

delete()

delete(string  $key, integer  $timeout) : boolean

Delete a key.

Parameters

string $key

The key.

integer $timeout

Expiration time in seconds.

Returns

boolean —

True on success.

get()

get(mixed  $keys) : mixed

Get data associated with a key.

Parameters

mixed $keys

The key or an array of keys.

Returns

mixed —

The string/array on success (return type is the type of $keys), false on failure.

set()

set(string  $key, string  $var,   $expire) : boolean

Set the value of a key.

Parameters

string $key

The key.

string $var

The data to store.

$expire

Returns

boolean —

True on success.

replace()

replace(string  $key, string  $var,   $expire) : boolean

Replace the value of a key.

Parameters

string $key

The key.

string $var

The data to store.

$expire

Returns

boolean —

True on success, false if key doesn't exist.

lock()

lock(string  $key) 

Obtain lock on a key.

Parameters

string $key

The key to lock.

unlock()

unlock(string  $key) 

Release lock on a key.

Parameters

string $key

The key to lock.

flush()

flush() 

Mark all entries on a memcache installation as expired.

stats()

stats() : array

Get the statistics output from the current memcache pool.

Returns

array —

The output from Memcache::getExtendedStats() using the current configuration values.

failover()

failover(string  $host, integer  $port) 

Failover method.

Parameters

string $host

Hostname.

integer $port

Port.

Throws

\Horde_Memcache_Exception

serialize()

serialize() : string

Serialize.

Returns

string —

Serialized representation of this object.

unserialize()

unserialize(string  $data) 

Unserialize.

Parameters

string $data

Serialized data.

Throws

\Exception
\Horde_Memcache_Exception

_set()

_set(string  $key, string  $var,   $expire,   $len = null) : boolean

Set the value of a key.

Parameters

string $key

The key.

string $var

The data to store (serialized).

$expire
$len

Returns

boolean —

True on success.

_lockAdd()

_lockAdd(string  $key) 

Small wrapper around Memcache[d]#add().

Parameters

string $key

The key to lock.

_key()

_key(string  $key) : string

Obtains the md5 sum for a key.

Parameters

string $key

The key.

Returns

string —

The corresponding memcache key.

_getOSKeyArray()

_getOSKeyArray(  $key,   $length) : array

Returns the key listing of all key IDs for an oversized item.

Parameters

$key
$length

Returns

array —

The array of key IDs.

_getFlags()

_getFlags(integer  $count) : integer

Get flags for memcache call.

Parameters

integer $count

Returns

integer