5   Cache

5.1   About the cache

The result of a query made with the cache objects will be eitherretrieved from the cache if the entry is already there or recovered from the database and inserted into the cache.

The result of the query stored in the cache does not depend on the used hydratation system.

5.2   Simple query

A query intended to use the cache is done by retrieving the object CCMBenchmark\Ting\Query\Cached\Query from the Repository.

To proceed, just call the object and specify the duration it should remain in the cache and the cache key:

$query = $this->getCachedQuery('SELECT ...');
$query->setTtl(300); // 5mn
$query->setCacheKey('listOfUser');

5.3   Prepared query

For a prepared statement you must retrieve the object CCMBenchmark\Ting\Query\Cached\PreparedQuery from the Repository.

To proceed, just call the object and specify the duration it should remain in the cache and the cache key:

$query = $this->getCachedPreparedQuery('SELECT ...');
$query->setTtl(300); // 5mn
$query->setCacheKey('listOfUser');