Caching: Codeigniter VS. Fuel

edited March 2013 in Feature Requests
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

  • edited 6:35AM
    Part of the reason FUEL has it's own library is because the CI Cache library use to be pretty limited in 1.7x and was only setup to cache stuff sent to the Output class if I remember correctly. In 2.0, there was a Cache driver added. We've considered using the CI cache, however, the Fuel Cache library seems to do the job pretty well and includes a "group" parameter which allows us easily group cache files together.

    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.
  • edited 6:35AM
    I have a couple of URLs setup as controllers, one for login and one for signup that are web forms that don't need to be cached. If I set that use_page_cache parameter, will it cache the views that these controllers load as well? Or does the traditional controller > view method bypass this cache setting?

    Thanks again!
    Erik
  • edited 6:35AM
    Also, in our benchmarking tests using the CI profiler, it appears that $this->output->cache(n) CI caching seem to be an order of magnitude faster than fuel caching. Fuel caching saves about 25% of page load time whereas CI caching saves about 90%.

    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.
  • edited 6:35AM
    One additional question: Does setting the cache to "yes" in the Page edit view of the CMS do the same thing as if you set the use_page_cache parameter in MY_fuel.php?
  • edited 6:35AM
    To answer your first question, that would bypass the fuel cache settings since it's not being routed through the page_router controller.

    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.
  • edited 6:35AM
    Here's what I ended up doing. For each page I want to use the CI caching, I set up a controller called "home.php" where each function in that controller corresponds with a route I have defined in routes.php. Each controller has this logic (inside of home.php):

    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
Sign In or Register to comment.