Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Caching one section of a CodeIgniter page

I'm using codeigniter to create a web app. I'm creating the drop down menus in the header. These are included on every page using load->view(). To populate the menus some quite complex SQL is used. The contents on the menu will change infrequently (once/twice a week), whereas the rest of the data on the page is constantly changing.

Therefore I don't want the overhead of running this SQL everytime a page is loaded. I looked at using CI caching but its on a page level. I really only want to cache a small segment.

What do you think the best approach to this is? I thought about writing this to a text file, but then you'd have to manually run the code to write this every so often.

like image 956
Alex Avatar asked Mar 24 '10 12:03

Alex


2 Answers

Take a look at the query caching page, or alternatively you can use a caching library to cache sections of a page (preferred method IMHO) take a look at KhCache.

like image 119
fire Avatar answered Sep 30 '22 00:09

fire


Another good caching library I have found is from Phil Sturgeon. http://github.com/philsturgeon/codeigniter-cache

It allows caching models, libraries, or just partial caching like you describe.

like image 35
Eric Avatar answered Sep 30 '22 01:09

Eric