Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Is there ever a time when you should use caching? Like for frequently updated pages? Or, should you always cache?

Please give examples and reason?

share|improve this question
    
I think this is one of those "you'll know it when you see it" questions. If you want more concrete answers, the question may need to be more specific. –  JasonBirch Jul 18 '10 at 6:27
add comment

3 Answers

up vote 4 down vote accepted

Guess it depends on what you mean by cache.

  1. Database query caching - in many cases it makes sense to cache queries in memcached or even serialized to disk

  2. Page fragment caching - if you have portions of your page that are semi-dynamic, it can sometimes make sense to persist those to memory or disk rather than having to re-generate them on every page load

  3. Reverse proxy - an intelligent (or not-so-intelligent) layer that stores snapshots of your fully rendered pages and presents these as static pages to the client based on strategies you set.

  4. Client side caching - through the intelligent choice of Expires and other HTTP headers, you can ensure that your clients only request files from your site as needed

All of these play a role in site optimization, and use is determined by how dynamic your data is, whether the client is logged in, and countless other factors. The simple answer is to cache wherever you can, at the level which consumes the fewest resources, without compromising user experience.

share|improve this answer
1  
+1 for database query caching. It's very useful for query that can be expensive and won't produce different result in short amount of time. It's a good way to reduce the average number of SQL query in your page. –  HoLyVieR Jul 18 '10 at 15:14
add comment

A web site which tells you the current time of day.

share|improve this answer
1  
A legitimate answer, but probably should be a comment instead ;) –  DisgruntledGoat Jul 18 '10 at 16:40
add comment

I'm assuming you meant 'shouldn't use caching?' otherwise you should really always use caching for pages that need it. (lots of server side rendering and sql...).

A cache is used to send out pre-rendered pages opposed doing the logic and the database queries for every single request. drasticly speeds up everything. An option is to just clear the cache more often.. not necisarily turn if off.

There are times where you want no cache.. like an admin panel or something that has to be updated immedietly, every time.

A cache should be used for pages: that don't change a lot or have to be constantly parsed by php if there as a lot of work to render the page like database calls or a lot of utilitly scripts. if it is requested a lot. like a home page.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.