If you have dynamic part then You should not cache complete View
, but only partials
instead (my example above).
Cache in Phalcon means when something is rendered then it is written to Cache backend.
If You want to cache big view then You can make placeholders
inside pre-cached view data
and later replace with dynamic content, but it will consume a lot of CPU time. Javascript will do it much faster because of client CPU resources.
JS implementation can be:
- Cache header
- calculate variables and add Javascript KV array of calculated variables in the
HEAD
or footer
- dump cached view content (if exists of cause)
- add JS handlers on DOM page load to invoke KV-replacement on DOM level -
<div id="#myVar"></div>
or whatever You want to display.
- best part of it can be that variable mapping can have some kind of AJAX URIs so You can implement simple Ajax widgets also.
I am using this Ajax approach to integrate KnockoutJS forms/view-models. Phalcon View has nothing to do with PHP variables on request scope
- load form viewModel (my-form.ko.js)
- display form, without any
<?php echo $this->view->var; ?>
- bind KnockoutJS library -
var vm = new MyForm(); ko.applyBindings(). vm.loadById( ... );