8 Cache¶
8.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.
8.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:
use CCMBenchmark\Ting\Repository\Repository;
use CCMBenchmark\Ting\Repository\MetadataInitializer;
class SampleRepository extends Repository implements MetadataInitializer
{
public function getUsers()
{
$query = $this->getCachedQuery('SELECT ...');
$query->setTtl(300); // 5mn
$query->setCacheKey('listOfUser');
// ...
8.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:
use CCMBenchmark\Ting\Repository\Repository;
use CCMBenchmark\Ting\Repository\MetadataInitializer;
class SampleRepository extends Repository implements MetadataInitializer
{
public function getUsers()
{
$query = $this->getCachedPreparedQuery('SELECT ...');
$query->setTtl(300); // 5mn
$query->setCacheKey('listOfUser');
// ...