我有以下功能,但它不是缓存。我有什么遗漏的吗?环境:Doctrine Common 和 DBAL、PHP、MySQL。我不应该将缓存 ID 设置为变量吗?
function getGeo($latitude, $longitude, $radius, $numResults, $volunteerPid, $startPosition, $pageSize)
{
$cacheDriver = new Doctrine\Common\Cache\ArrayCache();
$geoQuery = $cacheDriver->fetch($volunteerPid);
if ($geoQuery === false) {
$geoQuery = $this->connection->prepare("call sproc_qryGeo($latitude, $longitude, $radius, $numResults, $volunteerPid, $startPosition, $pageSize)");
$cacheDriver->save($volunteerPid, $geoQuery);
echo "NOT CACHED";
}
return $geoQuery;
}
最佳答案
来自 cache types definintions on Doctrine site ArrayCache 具有请求的生命周期。因此,重新加载页面后,您的缓存就会消失。
所以,如果这是您的情况 - 考虑另一个缓存存储,Doctrine 支持其中的很多。
关于php - 缓存不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34771873/