Caching: Codeigniter VS. Fuel
Hello everyone,
I'm trying to understand the difference between the caching features that both Codeigniter and Fuel offers. I did a search on the forums and in the user guide for both docs (CI and Fuel) and it seems like there is a basic CI method where you use $this->output->cache(n); for a controller that's loading a view. Fuel, on the other hand leverages a third-party Cache library developed by Al James.
Can someone help me understand how the caching features of both CI and Fuel can be leveraged? I'm looking at improving the load times of my static pages that are stored in Fuel (both with local view copies and database copies that are managed by Fuel users). Would simply turning on the Cache setting to "on" for all my static pages do the same as the equivalent $this->output->cache(n); would if all my static Fuel pages were turned into the traditional controller loading a view method?
Erik
Comments
For FUEL, you can set the "$config['use_page_cache'] = TRUE' in MY_fuel.php to turn on caching for both the "opt-in" view pages and the CMS pages (basically any file that goes through the fuel/modules/fuel/controllers/page_router.php controller). By default it is set to "cms" which will only cache pages from the CMS.
Thanks again!
Erik
This is the main reason I'm exploring the two options to see if there is a way I can modify Fuel to take advantage of CI's caching mechanism for both the opt-in view pages and the CMS pages.
With regards to the cache timing, are you comparing a normal controller view that's cached to a FUEL page? If so, the FUEL page caching doesn't really kick in until after the appropriate page to be rendered has been determined. It also does some post processing to add the inline editing stuff. So it may not be FUEL cache but more how pages are being rendered that is causing it to be slower. It will always be quicker to use a straight controller with caching since it requires a minimal amount of processing. Also, the per page cache setting is the same as setting it in the use_page_cache but is at the page level.
function about() { // Set the page caching to 60 minutes $this->output->cache(60); // load the fuel_page library class and pass it the view file you want to load from the CMS $this->load->module_library(FUEL_FOLDER, 'fuel_page', array('location' => 'about', 'render_mode' => 'cms')); $this->fuel_page->add_variables($this->page_data); $this->fuel_page->render(); }
I had to add a bunch of routes into routes.php, and it looks like this:
//This used to be the default controller //$route['default_controller'] = 'fuel/page_router'; //now these are, so we can use CI caching //-----------CMS pages----------- $route['default_controller'] = 'home'; $route['about'] = 'home/about'; $route['contact'] = 'home/contact'; $route['faq'] = 'home/faq'; $route['404_override'] = 'fuel/page_router';
This allows me to leverage the power of CI caching, which by the way has drastically helped the performance of the website and allows me to still create pages in the CMS (they just won't be cached unless I set them up to in both the home controller and the routes.php file.
It would be GREAT if the Fuel guys could develop a way to "hack" the way CI does its caching on the output class to prevent us from having to create routes and custom controller functions for the pages we want cached. Would welcome ideas anyone has on ways to accomplish this from Fuel's perspective.
Erik