PDA

View Full Version : Dynamic page caching



keyboard
03-07-2013, 05:38 AM
Hey all :)
First off, I'd like to start with this:
Where should you store page caches? Flat files or DB?

Secondly: What's the advantage of caching a page that is updated very frequently (e.g. fb) or a page that is customized to a single user?
Thanks :)

djr33
03-07-2013, 06:01 AM
Caching can be implemented in many ways. It trades more storage space for less processing.

What exactly are you trying to do? The answer will depend on that.


Where should you store page caches? Flat files or DB?Depends on your goals. You might store cached information in the db if it's something that takes a lot to process (perhaps some accumulated value from calculating something about 50 entries). Or you might store a full HTML page as a file after generating it one time from the database.
As an extreme example, if you're making images using PHP's GD library, you'd want to save those as files rather than re-process them each time-- that's a form of caching too.


Secondly: What's the advantage of caching a page that is updated very frequently (e.g. fb) or a page that is customized to a single user?Probably none. It might be a waste of space then. You need to use the cache more than 1 time for it to be useful. In fact, if the page is constantly being updated, the cache could be counterproductive-- it might stop the user from seeing the newest content (unless that's acceptable).

keyboard
03-08-2013, 11:48 AM
Hmmm... I remember a while ago Adrain says FB caches a lot... Adrian? :p

djr33
03-08-2013, 06:18 PM
Facebook isn't cached, not entirely. But it certainly can use caching to save frequently accessed parts of the site.

Another option (something I've set up on one of my sites) is to check when the content was last updated (you need a "last updated" table in your database, or to save a date in your existing tables) then:
1. check if there is a cached version.
2. If so, is that cached version newer than the latest update?
3. If so, display it.
4. If no accurate cached version is found, re-process and save that in the cache.