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

How to cache a page with some dynamic content?

For example, A page with the content of an article (e.g. stores in the database with article ID = 1) and a "sign in" button.

The button will be replaced by the user's name after signed in.

How to cache the page?

edited Feb '16

There are multiple ways how to do that:

1) Best performance you will achieve, when you cache whole page content and after the page rendered you replace or push dynamic elements via AJAX. Be carefull, that this choice will not work on clients without JS.

2) Second way is not to cache whole page content, but cache only static blocks which have the same content. This will work always.



31.3k

Thanks!

I prefer with the second way.

And how to cache the certain content in the above example? with File cache or Memcache?

There are multiple ways how to do that:

1) Best performance you will achieve, when you cache whole page content and after the page rendered you replace or push dynamic elements via AJAX. Be carefull, that this choice will not work on clients without JS.

2) Second way is not to cache whole page content, but cache only static blocks which have the same content. This will work always.

edited Feb '16

Hi, it depeds whether your server is memory bound (then use File cache) or IO bound (then use Memcached). If none of the options use preferably Memcached or Redis for best performance.

Easies way to setup caching is to use standard Phalcon components via modelsCache and viewsCache services.