Reduce the number of requestAction requests using Cache
Cakephp 1.2 documentation says that if requestAction is used without caching, then it can slow down performance.
If used without caching requestAction can lead to poor performance. It is rarely appropriate to use in a controller or model.
And really, think for yourself, every time you browse the site, in addition to basic queries, a lot of small ones are made to the database using requestAction, for example ...
And like true politicians, they say WHAT can happen, without saying how to avoid it.
I give an example of how I deal with this.
Briefly about how requestAction works:
requestAction is usually used in a view file (views folder). from the view file, you make a request to another page, and get the value.
the requestAction syntax is as follows:
Cakephp tells it to make a request at the address of the website.site.com / articles / home
in the controller itself to which requestAction refers; you need to register return; now we can safely add to $ this-> requestAction ('/ articles / home'); next lines After that, we once make a request to the database, write everything to a file. and the rest of the times we read from the file. If as a result of some problems on the part of the UFO, we can not read the file from the cache, that's okay. Again, we make a request to the database, and again we write to the file (the priest had a dog ...) and now every time we update this list, if we added / changed something, we don’t forget to overwrite Cache: crosspost from my blog
If used without caching requestAction can lead to poor performance. It is rarely appropriate to use in a controller or model.
And really, think for yourself, every time you browse the site, in addition to basic queries, a lot of small ones are made to the database using requestAction, for example ...
And like true politicians, they say WHAT can happen, without saying how to avoid it.
I give an example of how I deal with this.
Briefly about how requestAction works:
requestAction is usually used in a view file (views folder). from the view file, you make a request to another page, and get the value.
the requestAction syntax is as follows:
$this->requestAction('/articles/home');
Cakephp tells it to make a request at the address of the website.site.com / articles / home
in the controller itself to which requestAction refers; you need to register return; now we can safely add to $ this-> requestAction ('/ articles / home'); next lines After that, we once make a request to the database, write everything to a file. and the rest of the times we read from the file. If as a result of some problems on the part of the UFO, we can not read the file from the cache, that's okay. Again, we make a request to the database, and again we write to the file (the priest had a dog ...) and now every time we update this list, if we added / changed something, we don’t forget to overwrite Cache: crosspost from my blog
function home(){
$out = $this->Article->find('all');
Cache::write('articleHome', $out);
return $out;
}
$out = Cache::read('articlesHome');
if(empty($out)){
$out = $this->requestAction('/articles/home');
}
Cache::write('articleHome', $out);