Part of the EllisLab Network
   
 
Small question regarding caching
Posted: 05 March 2009 04:53 PM   [ Ignore ]  
Grad Student
Rank
Total Posts:  45
Joined  02-17-2009

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

Profile
 
 
Posted: 05 March 2009 05:25 PM   [ Ignore ]   [ # 1 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  3782
Joined  04-25-2008

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

 Signature 

Remember the 8 Ps: Perfect Planning and Prior Preparation Prevents Piss-Poor Performance.


Not sure where to start with your project? Need some inspiration? Check out my CodeIgniter Resources thread

Profile
 
 
Posted: 05 March 2009 05:53 PM   [ Ignore ]   [ # 2 ]  
Grad Student
Rank
Total Posts:  45
Joined  02-17-2009

Okay, thanks smile

Profile
 
 
Posted: 06 April 2009 04:12 AM   [ Ignore ]   [ # 3 ]  
Grad Student
Avatar
Rank
Total Posts:  81
Joined  06-06-2007

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://codeigniter.com/user_guide/general/caching.html

Mei

 Signature 

Web Development in north Wales
mei.gwilym.net

Profile
 
 
Posted: 06 April 2009 06:03 AM   [ Ignore ]   [ # 4 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  3782
Joined  04-25-2008

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.

 Signature 

Remember the 8 Ps: Perfect Planning and Prior Preparation Prevents Piss-Poor Performance.


Not sure where to start with your project? Need some inspiration? Check out my CodeIgniter Resources thread

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 819, on March 11, 2010 10:15 AM
Total Registered Members: 119641 Total Logged-in Users: 28
Total Topics: 125857 Total Anonymous Users: 3
Total Replies: 662258 Total Guests: 345
Total Posts: 788115    
Members ( View Memberlist )