php – Caching one section of a CodeIgniter page-ThrowExceptions

Exception or error:

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.

How to solve:

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.


Another good caching library I have found is from Phil Sturgeon.

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

Leave a Reply

Your email address will not be published. Required fields are marked *