The cache correct work in find and findOne of model.
//service.php
$di->set(
"modelsCache",
function () use ($config){
$frontCache = new \Phalcon\Cache\Frontend\Data(array(
"lifetime" => $config->redis->lifetime
));
$cache = new \Phalcon\Cache\Backend\Redis($frontCache, [
'prefix' =>$config->redis->prefix.'db_',
'lifetime' => $config->redis->lifetime,
'host' => $config->redis->host,
'port' => $config->redis->port,
'persistent' => $config->redis->persistent,
]);
return $cache;
}
);
//model Country
public static function getAll($lang='en',$cache)
{
$sql="select c.*,COALESCE(transliterate((select a.alternate_name...";
$countries= new Country();
return new Resultset(null, $countries, $countries->getReadConnection()->query($sql),$cache);
}
Call model from controller
$time_start = microtime(true);
Country::getAll($this->lang,$this->modelsCache);
$time_end = microtime(true);
$time = $time_end - $time_start;
echo $time;
The result 1.8994641304016 to 2.0657551288605 seconds. The result corect return list of countries.
Connection like
var_dump($countries->getReadConnection()->query($sql));
Return
object(Phalcon\Db\Result\Pdo)#256 (8) { ["_connection":protected]=> object(Phalcon\Db\Adapter\Pdo\Postgresql)#253 (13) { ["_eventsManager":protected]=>
Phalcon 3.0.3 Ubuntu php7.0