Alex
Alex

Reputation: 6665

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.

Upvotes: 7

Views: 5777

Answers (2)

Eric
Eric

Reputation: 1197

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.

Upvotes: 2

fire
fire

Reputation: 21541

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.

Upvotes: 5

Related Questions