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 partials from controller

So I have this ugly mess here, that loops threw some data, and shows partials depending on the data.


The amount of mb it takes to load the web page is huge. Is there anyway to make this use less memory?

( There can be up to 10 partials )

foreach($sections as $section){
        if($section['name'] == $page){
            $this->view->partial($section['name'], ['settings' => (object)$section['settings']]);

You mean amount of MB at PHP side or at the client side (browser)?

The client side

There is really not much html in the different partials, maybe like 3 lines, but when I run the loop the size goes from 300 kb to 2 mb. That's a lot.. Is there anyway to make it less?

Well, that's question regarding your app conception I guess. If you have large amounts of data to return to the clients, you could optimize it by using pagination, e.g. return only first N rows, then have pagination do the navigation between pages.

And then you could use regular optimization techniques such as minifing CSS/JS stuff etc. Last but not least - all textual content shall be sent in a compressed format to the clients in order to minimize network latency. But eventually they'll have the same issue if there's a lot of content, after they decompress it. No way around this but to make your responses paginated e.g. returning parts of response instead of full response.

And this has nothing to do with the Phalcon, PHP, etc. It's more of a general problem - how much of the data browsers could handle w/o eating all RAM on the client side, usually we see SPA apps which simply make browsers crawl to it's knees with the amount of data they have to store on the client side....

Also you could cache the intermediate responses - data from DB and compiled static template outputs. But that won't do any help to the clients, only your server side.