We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Cache Performance Comparison: File vs Memcache vs APC vs Mongo vs Xcache vs Redis

I would like to help me to know the different types of cache in Phalcon.

  • What consumes less resources?
  • What is faster?
  • and when is a good one or the other?


85.5k

redis benchmarks on 2 x xeon with 8 gb ram

====== SET ======
  100000 requests completed in 1.58 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

99.94% <= 1 milliseconds
99.95% <= 2 milliseconds
100.00% <= 2 milliseconds
63291.14 requests per second

====== GET ======
  100000 requests completed in 1.57 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

99.99% <= 1 milliseconds
100.00% <= 1 milliseconds
63897.76 requests per second

i wound remove file from your question. i guess if you have some 2 k $ ssds you might reach insane speeds, but i think the problem comes from wasted time reading this file.

We can say that?

Redis > Xcache > Memcache > APC > File > Mongo



85.5k

i see that xcache is outdated, no realease for php7 or in the past 2 years,

betheen redis and memcache you have to read here https://www.infoworld.com/article/3063161/application-development/why-redis-beats-memcached-for-caching.html

never used mongo or apc

never used mongo or apc

and you think of OPcache?

https://php.net/manual/es/book.opcache.php



85.5k
edited Sep '16

as far as i know ( i could be wrong tho ) opcache is used by php itself, it stores varaible data and use it itself.

Havent see any application usuage of it. I always run php with opcache enabled.

How I cache my applications...

public function indexAction() {

        if (false === $this->view->getCache()->exists(\Shop\Enums\Caches::$action_home_index)) {
            //db queries
            $this->view->setVar....
        }   

        //some variable i need always for example
        $this->view->setVar('showSlider', true); //because its not used in the action view but in the layout
}

in my view


<?php
    $cache = \Phalcon\Di::getDefault()->get('viewCache');

    $content = $cache->start(\Shop\Enums\Caches::$action_home_index);

    // If $content is null then the content will be generated for the cache
    if ($content === null) {
    //div bla bla bla
    // foreach records echo bla bla bla
    $cache->save();
    } else {

        echo $content;
    }
public static action_home_index = "action-home-index";

the service


$this->di->set('viewCache', function(){

            $frontCache = new \Phalcon\Cache\Frontend\Output(array(
                "lifetime" => 172800 //2 days i am not sure about this so you gacve toi check it yourself
            ));

            $cache = new \Phalcon\Cache\Backend\Redis($frontCache, array(
                'host' => '127.0.0.1',
                'port' => 6379,
                "statsKey" => '_shop-view-cache-'
            ));

            if (APPLICATION_ENV === 'development'){
                $cache->flush();
            }

            return $cache;
        });

so at the end my whole action view is saved into a memory database that does 60k req/s

the responce time on prod with my config the debugger sais 5ms responce time.

i use this kind a cache 90% of the time. rest of the time i use basic phalcon orm cache as said in the docs

Im just using mostly memcache most of time.

edited Aug '17

Memcached is very simple and nice to use as a general-purpose cache store. For sessions - don't look any further.

I wouldn't even consider cache store systems which cannot run independently (i.e. APC).

MongoDB is best for storing documents (real app data). In that case Redis is probabbly what you need for caching app data.

File storage - just forget about it for a real world use case, I/O latency would cause problems under high load.



112
edited Aug '17

We can say that?

Redis > Xcache > Memcache > APC > File > Mongo

No,

If you need fast, for high load pure cache better be memcached over unix-socket.