I have a complex stored procedure that is run multiple times on a site developed in php. I have Doctrine on the system (I'm not a doctrine guru) from the previous developer. The stored procedure takes about 4.62 seconds to run and return results. I would like to cache the results but am unfamiliar with caching with Doctrine. The results are limited to 200 with 25 per page. One of my concerns is that the data can change often, so not sure how to get the site faster. Thanks.
EDIT
I found the files I was missing for Doctrine\Common\Cache and uploaded them.
I have the following function; however, it is not caching:
function getGeo($latitude, $longitude, $radius, $numResults, $volunteerPid, $startPosition, $pageSize)
{
$cacheDriver = new Doctrine\Common\Cache\ArrayCache();
if ($numResults == 5) {
if ($cacheDriver->contains($volunteerPid)) {
$geoQuery = $cacheDriver->fetch($volunteerPid);
echo "Number results equals 5 and has cache";
} else {
$geoQuery = $this->connection->prepare("call sproc_qryGeoPrecint($latitude, $longitude, $radius, $numResults, $volunteerPid, $startPosition, $pageSize)");
$cacheDriver->save($volunteerPid, $geoQuery);
echo "Number results equals 5 and has NO cache";
}
} else {
if ($cacheDriver->contains($volunteerPid)) {
$geoQuery = $cacheDriver->fetch($volunteerPid);
echo "Number results equals 200 and has cache";
} else {
$geoQuery = $this->connection->prepare("call sproc_qryGeoPrecint($latitude, $longitude, $radius, $numResults, $volunteerPid, $startPosition, $pageSize)");
$cacheDriver->save($volunteerPid, $geoQuery);
echo "Number results equals 200 and has NO cache";
}
}
return $geoQuery;
}
You might be looking for the Doctrine result cache. You can configure the query that executes the stored procedure to use the result cache. If the data changes often you can set a short lifetime for the cache and/or set up an event listener to invalidate the cache when relevant data is changed.