2

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?

1
  • 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
    Commented Jul 18, 2010 at 6:27

3 Answers 3

5

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.

1
  • 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
    Commented Jul 18, 2010 at 15:14
3

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

1
  • 1
    A legitimate answer, but probably should be a comment instead ;) Commented Jul 18, 2010 at 16:40
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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