jordz Posted April 29, 2010 Share Posted April 29, 2010 Hey everyone, I have been pondering over caching, I would just like to know how to use it and where would I start? I need to create a system (Im assuming using caching) that will (in my site) get the Top Photo of the Day, Week, Month, etc? How would I go about this? I understand caching will take some strain of a database if I were query lots all the time? Correct me if I'm wrong? Any help would be appreciated. Many Thanks Jordan Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 29, 2010 Share Posted April 29, 2010 There are many different caching methods and the correct one would depend on many factors. BUt, for what you are asking I would do the following: Create a secondary table ("top_photos") with columns for "day", "week", "month", etc. As well as a field for "last_updated". When loading a page where you want to display those photos. That table would only ever have one record. When loading a page where you need the top photos you would query that table for the record. Before using the data, however, the code would check the last_updated timestamp. If more than 24 hours old it would qwuery the tables with the actual data to programatically determine the top photos for day, week, month and then update the record in the "top_photos" table. So, you would only need to query the single record in that table to get the top photos - which should be very fast. Only once a day would you run the more intensive query to update that table. Quote Link to comment Share on other sites More sharing options...
jordz Posted April 29, 2010 Author Share Posted April 29, 2010 I should have actually mentioned that this would be done on photo views, my bad for not being descriptive enough? So what you're saying is have on record for every photo? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.