CodeIgniter Forums

Full Version: Small question regarding caching
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Las3r[/eluser]
I read the userguide about caching and it says you can only cache "stuff" that is being served to a view, from within a controller.

Now i have the following function:

1) Loads a txt file (150 kb .txt file)
2) makes a multidimensional array from all the data
3) my site fetches info from this array

This array doesn't need to be loaded every time a user visits a page that utilizes this array, it should become available continuesly (the 150kb .txt file rarely gets updated (every 2 months or so)).

How can I have this array globally available without parsing all the contents to the controller every time user visits that page?

Can I use caching for this puprose?

Erik

El Forum

[eluser]TheFuzzy0ne[/eluser]
You can't. The data is dynamic, and can't be cached statically. Caching is for static pages.

El Forum

[eluser]Las3r[/eluser]
Okay, thanks Smile

El Forum

[eluser]meigwilym[/eluser]
I'm quite sure that TheFuzzyOne is incorrect. Caching is specifically for dynamic pages, to reduce load on databases etc.

Take a look on the user guide, you can probably cache the page with just one line

http://ellislab.com/codeigniter/user-gui...ching.html

Mei

El Forum

[eluser]TheFuzzy0ne[/eluser]
I know that dynamically generated pages can be cached, but to my knowledge, those pages must become static. I'm not sure if it would work if you had to display say a username in the header of your page. From what I understand, if you cache a page that generates differently for each user, every user will get the same page (i.e the same username showing). I'd be interested to know if it does work, though.

I'd suggest you make your own caching function. You can simply store the serialized array in a file; load it and unserialize if when you need it.