• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Small question regarding caching

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?


You can't. The data is dynamic, and can't be cached statically. Caching is for static pages.

Okay, thanks Smile

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



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.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.