Jump to content

Getting Started with a Caching system? How to use it and so on?


jordz

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.