Cache ORM not improve performance !

I can not get an improvement in the return of database values ​​using cache, read all documentation (https://docs.phalconphp.com/en/latest/reference/models-cache.html), however, still did not get success.

I started the service in the container (DI) this way:

$container->set('modelsCache', function() {
    $front = new Phalcon\Cache\Frontend\Data(array('lifetime' => 86400));
    $memcached = array('host' => '127.0.0.1', 'port' => '11211');
    return (new Phalcon\Cache\Backend\Memcache($front, $memcached));
});

Also, the cache was created in the controller action:

$cache = array('key' => 'my-cache', 'lifetime' => 300);
$conditions = array('cache' => $cache);
$this->view->topics = Topics::find($conditions);

Then I consulted in many ways, including how below:

$this->view->topics = $this->modelsCache->get('my-cache');

But in any way I could get better performance than a normal query to the database.

Am I doing something wrong! Anyone who can help, I would be grateful!



9.8k

Make everything else as fast as possible before doing any caching. Caching of small objects isn't as fast as you might think.



848

Strange, I did the same cache content from the Memcached extension and it was 10 times faster while consuming 1/4 of processing.



9.8k

I didn't say don't cache... Just said that caching should be your last option. Optimize everything else before you cache and you might find that you don't need to cache at all... Memory is not a super cheap resource, especially in the enterprise with hundreds of thousands of users. All I'm saying is caching should be the last thing you do to improve performance... Not the first.