class RedisCache extends CacheProvider (View source)

Redis cache provider.

Constants

DOCTRINE_NAMESPACE_CACHEKEY

Methods

void
setNamespace(string $namespace)

Sets the namespace to prefix all cache ids with.

string
getNamespace()

Retrieves the namespace that prefixes all cache ids.

mixed
fetch(string $id)

Fetches an entry from the cache.

mixed[]
fetchMultiple(array $keys)

Returns an associative array of values for keys is found in cache.

boolean
contains(string $id)

Tests if an entry exists in the cache.

boolean
save(string $id, mixed $data, int $lifeTime = 0)

Puts data into the cache.

boolean
delete(string $id)

Deletes a cache entry.

array|null
getStats()

Retrieves cached information from the data store.

boolean
flushAll()

Flushes all cache entries, globally.

boolean
deleteAll()

Deletes all cache entries in the current cache namespace.

array
doFetchMultiple(array $keys)

Default implementation of doFetchMultiple. Each driver that supports multi-get should owerwrite it.

mixed|boolean
doFetch(string $id)

Fetches an entry from the cache.

boolean
doContains(string $id)

Tests if an entry exists in the cache.

boolean
doSave(string $id, string $data, int $lifeTime = 0)

Puts data into the cache.

boolean
doDelete(string $id)

Deletes a cache entry.

boolean
doFlush()

Flushes all cache entries.

array|null
doGetStats()

Retrieves cached information from the data store.

void
setRedis(Redis $redis)

Sets the redis instance to use.

Redis|null
getRedis()

Gets the redis instance used by the cache.

integer
getSerializerValue()

Returns the serializer constant to use. If Redis is compiled with igbinary support, that is used. Otherwise the default PHP serializer is used.

Details

void setNamespace(string $namespace)

Sets the namespace to prefix all cache ids with.

Parameters

string $namespace

Return Value

void

string getNamespace()

Retrieves the namespace that prefixes all cache ids.

Return Value

string

mixed fetch(string $id)

Fetches an entry from the cache.

Parameters

string $id The id of the cache entry to fetch.

Return Value

mixed The cached data or FALSE, if no cache entry exists for the given id.

mixed[] fetchMultiple(array $keys)

Returns an associative array of values for keys is found in cache.

Parameters

array $keys Array of keys to retrieve from cache

Return Value

mixed[] Array of retrieved values, indexed by the specified keys. Values that couldn't be retrieved are not contained in this array.

boolean contains(string $id)

Tests if an entry exists in the cache.

Parameters

string $id The cache id of the entry to check for.

Return Value

boolean TRUE if a cache entry exists for the given cache id, FALSE otherwise.

boolean save(string $id, mixed $data, int $lifeTime = 0)

Puts data into the cache.

If a cache entry with the given id already exists, its data will be replaced.

Parameters

string $id The cache id.
mixed $data The cache entry/data.
int $lifeTime The lifetime in number of seconds for this cache entry. If zero (the default), the entry never expires (although it may be deleted from the cache to make place for other entries).

Return Value

boolean TRUE if the entry was successfully stored in the cache, FALSE otherwise.

boolean delete(string $id)

Deletes a cache entry.

Parameters

string $id The cache id.

Return Value

boolean TRUE if the cache entry was successfully deleted, FALSE otherwise. Deleting a non-existing entry is considered successful.

array|null getStats()

Retrieves cached information from the data store.

The server's statistics array has the following values:

  • hits Number of keys that have been requested and found present.

  • misses Number of items that have been requested and not found.

  • uptime Time that the server is running.

  • memory_usage Memory used by this server to store items.

  • memory_available Memory allowed to use for storage.

Return Value

array|null An associative array with server's statistics if available, NULL otherwise.

boolean flushAll()

Flushes all cache entries, globally.

Return Value

boolean TRUE if the cache entries were successfully flushed, FALSE otherwise.

boolean deleteAll()

Deletes all cache entries in the current cache namespace.

Return Value

boolean TRUE if the cache entries were successfully deleted, FALSE otherwise.

protected array doFetchMultiple(array $keys)

Default implementation of doFetchMultiple. Each driver that supports multi-get should owerwrite it.

Parameters

array $keys Array of keys to retrieve from cache

Return Value

array Array of values retrieved for the given keys.

protected mixed|boolean doFetch(string $id)

Fetches an entry from the cache.

Parameters

string $id The id of the cache entry to fetch.

Return Value

mixed|boolean The cached data or FALSE, if no cache entry exists for the given id.

protected boolean doContains(string $id)

Tests if an entry exists in the cache.

Parameters

string $id The cache id of the entry to check for.

Return Value

boolean TRUE if a cache entry exists for the given cache id, FALSE otherwise.

protected boolean doSave(string $id, string $data, int $lifeTime = 0)

Puts data into the cache.

Parameters

string $id The cache id.
string $data The cache entry/data.
int $lifeTime The lifetime. If != 0, sets a specific lifetime for this cache entry (0 => infinite lifeTime).

Return Value

boolean TRUE if the entry was successfully stored in the cache, FALSE otherwise.

protected boolean doDelete(string $id)

Deletes a cache entry.

Parameters

string $id The cache id.

Return Value

boolean TRUE if the cache entry was successfully deleted, FALSE otherwise.

protected boolean doFlush()

Flushes all cache entries.

Return Value

boolean TRUE if the cache entries were successfully flushed, FALSE otherwise.

protected array|null doGetStats()

Retrieves cached information from the data store.

Return Value

array|null An associative array with server's statistics if available, NULL otherwise.

void setRedis(Redis $redis)

Sets the redis instance to use.

Parameters

Redis $redis

Return Value

void

Redis|null getRedis()

Gets the redis instance used by the cache.

Return Value

Redis|null

protected integer getSerializerValue()

Returns the serializer constant to use. If Redis is compiled with igbinary support, that is used. Otherwise the default PHP serializer is used.

Return Value

integer One of the Redis::SERIALIZER_* constants