class ExtMongoDBCache extends CacheProvider (View source)

MongoDB cache provider for ext-mongodb

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.

bool
saveMultiple(array $keysAndValues, int $lifetime = 0)

Returns a boolean value indicating if the operation succeeded.

bool
contains(string $id)

Tests if an entry exists in the cache.

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

Puts data into the cache.

bool
deleteMultiple(array $keys)

Deletes several cache entries.

bool
delete(string $id)

Deletes a cache entry.

array|null
getStats()

Retrieves cached information from the data store.

bool
flushAll()

Flushes all cache entries, globally.

bool
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|false
doFetch(string $id)

Fetches an entry from the cache.

bool
doContains(string $id)

Tests if an entry exists in the cache.

bool
doSaveMultiple(array $keysAndValues, int $lifetime = 0)

Default implementation of doSaveMultiple. Each driver that supports multi-put should override it.

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

Puts data into the cache.

bool
doDeleteMultiple(array $keys)

Default implementation of doDeleteMultiple. Each driver that supports multi-delete should override it.

bool
doDelete(string $id)

Deletes a cache entry.

bool
doFlush()

Flushes all cache entries.

array|null
doGetStats()

Retrieves cached information from the data store.

__construct(Collection $collection)

This provider will default to the write concern and read preference options set on the Database instance (or inherited from MongoDB or Client). Using an unacknowledged write concern (< 1) may make the return values of delete() and save() unreliable. Reading from secondaries may make contain() and fetch() unreliable.

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.

bool saveMultiple(array $keysAndValues, int $lifetime = 0)

Returns a boolean value indicating if the operation succeeded.

Parameters

array $keysAndValues Array of keys and values to save in cache
int $lifetime The lifetime. If != 0, sets a specific lifetime for these cache entries (0 => infinite lifeTime).

Return Value

bool TRUE if the operation was successful, FALSE if it wasn't.

bool 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

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

bool 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

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

bool deleteMultiple(array $keys)

Deletes several cache entries.

Parameters

array $keys Array of keys to delete from cache

Return Value

bool TRUE if the operation was successful, FALSE if it wasn't.

bool delete(string $id)

Deletes a cache entry.

Parameters

string $id The cache id.

Return Value

bool 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.

bool flushAll()

Flushes all cache entries, globally.

Return Value

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

bool deleteAll()

Deletes all cache entries in the current cache namespace.

Return Value

bool 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|false doFetch(string $id)

Fetches an entry from the cache.

Parameters

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

Return Value

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

protected bool 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

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

protected bool doSaveMultiple(array $keysAndValues, int $lifetime = 0)

Default implementation of doSaveMultiple. Each driver that supports multi-put should override it.

Parameters

array $keysAndValues Array of keys and values to save in cache
int $lifetime The lifetime. If != 0, sets a specific lifetime for these cache entries (0 => infinite lifeTime).

Return Value

bool TRUE if the operation was successful, FALSE if it wasn't.

protected bool 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

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

protected bool doDeleteMultiple(array $keys)

Default implementation of doDeleteMultiple. Each driver that supports multi-delete should override it.

Parameters

array $keys Array of keys to delete from cache

Return Value

bool TRUE if the operation was successful, FALSE if it wasn't

protected bool doDelete(string $id)

Deletes a cache entry.

Parameters

string $id The cache id.

Return Value

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

protected bool doFlush()

Flushes all cache entries.

Return Value

bool 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.

__construct(Collection $collection)

This provider will default to the write concern and read preference options set on the Database instance (or inherited from MongoDB or Client). Using an unacknowledged write concern (< 1) may make the return values of delete() and save() unreliable. Reading from secondaries may make contain() and fetch() unreliable.