class Memcache (View source)

An interface to the App Engine memory cache with an interface compatible with the "memcache" PHP extension (see http://php.net/manual/en/book.memcache.php)

All instances of this class use the same memory pool for their keys and values.

Methods

bool
add(string $key, mixed $value, int $flag = null, int $expire = 0)

Adds a new item to the cache. Will fail if the key is already present in the cache.

addServer($host)

This function is present only for compatibility and does nothing.

close()

This function is present only for compatibility and does nothing.

connect($host, $port = null, $timeout = 1)

This function is present only for compatibility and does nothing.

mixed
decrement(string $key, int $value = 1)

Decrements a cached item's value. The value must be a int, float or string representing an integer e.g. 5, 5.0 or "5" or the call with fail.

bool
delete(string $key)

Deletes an item from the cache.

bool
flush()

Removes all items from cache.

mixed
get(string|string[] $keys, int $flags = null)

Fetches previously stored data from the cache.

mixed
increment(string $key, int $value = 1)

Increments a cached item's value. The value must be a int, float or string representing an integer e.g. 5, 5.0 or "5" or the call with fail.

pconnect($host, $port = null, $timeout = 1)

This function is present only for compatibility and does nothing.

bool
replace(string $key, mixed $value, int $flag = null, int $expire = 0)

Replaces an existing item in the cache. Will fail if the key is not already present in the cache.

bool
set(string $key, mixed $value, int $flag = null, int $expire = 0)

Sets the value of a key in the cache regardless of whether it is currently present or not.

setCompressThreshold($threshold, $min_savings = 0.2)

This function is present only for compatibility and does nothing.

Details

bool add(string $key, mixed $value, int $flag = null, int $expire = 0)

Adds a new item to the cache. Will fail if the key is already present in the cache.

Parameters

string $key The key associated with the value added to the cache.
mixed $value The value to add to the cache.
int $flag This parameter is present only for compatibility and is ignored.
int $expire The delay before the item is removed from the cache. If $expire <= 2592000 then it is interpreted as the number of seconds from the time of the call to wait before removing the item from the cache. If $expire > 2592000 then it is interpreted as the absolute Unix epoch time when the value will expire.

Return Value

bool true if the item was successfully added to the cache, false otherwise.

addServer($host)

This function is present only for compatibility and does nothing.

Parameters

$host

close()

This function is present only for compatibility and does nothing.

connect($host, $port = null, $timeout = 1)

This function is present only for compatibility and does nothing.

Parameters

$host
$port
$timeout

mixed decrement(string $key, int $value = 1)

Decrements a cached item's value. The value must be a int, float or string representing an integer e.g. 5, 5.0 or "5" or the call with fail.

Parameters

string $key The key associated with the value to decrement.
int $value The amount to decrement the value.

Return Value

mixed On success, the new value of the item is returned. On failure, false is returned.

bool delete(string $key)

Deletes an item from the cache.

Parameters

string $key The key associated with the item to delete.

Return Value

bool true if the item was successfully deleted from the cache, false otherwise. Note that this will return false if $key is not present in the cache.

bool flush()

Removes all items from cache.

Return Value

bool true if all items were removed, false otherwise.

mixed get(string|string[] $keys, int $flags = null)

Fetches previously stored data from the cache.

Parameters

string|string[] $keys The key associated with the value to fetch, or an array of keys if fetching multiple values.
int $flags This parameter is present only for compatibility and is ignored. It should return the stored flag value.

Return Value

mixed On success, the string associated with the key, or an array of key-value pairs when $keys is an array. On failure, false is returned.

mixed increment(string $key, int $value = 1)

Increments a cached item's value. The value must be a int, float or string representing an integer e.g. 5, 5.0 or "5" or the call with fail.

Parameters

string $key The key associated with the value to increment.
int $value The amount to increment the value.

Return Value

mixed On success, the new value of the item is returned. On failure, false is returned.

pconnect($host, $port = null, $timeout = 1)

This function is present only for compatibility and does nothing.

Parameters

$host
$port
$timeout

bool replace(string $key, mixed $value, int $flag = null, int $expire = 0)

Replaces an existing item in the cache. Will fail if the key is not already present in the cache.

Parameters

string $key The key associated with the value that will be replaced in the cache.
mixed $value The new cache value.
int $flag This parameter is present only for compatibility and is ignored.
int $expire The delay before the item is removed from the cache. If $expire <= 2592000 then it is interpreted as the number of seconds from the time of the call to wait before removing the item from the cache. If $expire > 2592000 then it is interpreted as the absolute Unix epoch time when the value will expire.

Return Value

bool true if the item was successfully replaced in the cache, false otherwise.

bool set(string $key, mixed $value, int $flag = null, int $expire = 0)

Sets the value of a key in the cache regardless of whether it is currently present or not.

Parameters

string $key The key associated with the value that will be replaced in the cache.
mixed $value The new cache value.
int $flag This parameter is present only for compatibility and is ignored.
int $expire The delay before the item is removed from the cache. If $expire <= 2592000 then it is interpreted as the number of seconds from the time of the call to wait before removing the item from the cache. If $expire > 2592000 then it is interpreted as the absolute Unix epoch time when the value will expire.

Return Value

bool true if the item was successfully replaced the cache, false otherwise.

setCompressThreshold($threshold, $min_savings = 0.2)

This function is present only for compatibility and does nothing.

Parameters

$threshold
$min_savings