What is the purpose of CACHING?

I have seen many suggestions for caches to be cleared when making changes, which I have done as needed.

What is the real benefit / reason for caching? Faster browser load times? Less server load? Something else?

Whenever I have enabled it I get broken links/images and from my experience there seems to be no useful befit to caching at all.

Quote · 19 Mar 2010

Both.

Caching of frequently used information reduces the load on the database.

Image caching is not supported by some browsers and is off by default, and should stay that way.

I have also had problems with the caching system as well, and usally have it off. But it does help. I find if i leave either css or js caching off and the other on as well as the html caching, it works better for me.

https://www.deanbassett.com
Quote · 19 Mar 2010

Yes, I find the exact same thing.  I have only the css and html caching enabled.  If I add the js caching, my site takes even longer to load each page.  I've tested it out a dozen times or more, so I'm definitely not imagining this.  I was beginning to think I was the only one who was experiencing this.

No Signature at this time.
Quote · 20 Mar 2010

Caching,

PHP Caching to Speed up Dynamically Generated Sites

This entire site, like many, is built in PHP. PHP provides the power to simply 'pull' content from an external source, in the case of my site this is flat files but it could just as easily be an MySQL database or an XML file etc..

The downside to this is processing time, each request for one page can trigger multiple database queries, processing of the output, and formatting it for display... This can be quite slow on complex sites (or slower servers)

Ironically, these so-called 'dynamic' sites probably have very little changing content, this page will almost never be updated after the day it is written - yet each time someone requests it the scripts goes and fetches the content, applies various functions and filters to it, then outputs it to you...

Enter Caching

This is where caching can help us out, instead of regenerating the page every time, the scripts running this site generate it the first time they're asked to, then store a copy of what they send back to your browser. The next time a visitor requests the same page, the script will know it'd already generated one recently, and simply send that to the browser without all the hassle of re-running database queries or searches.

An Illustration

This example shows a request for a "News" page on a website, the News changes daily so it makes sense to have it in a database rather than as a static file so it can be easily updated and searched, The News page is a PHP script which does the following;

  • Connect to an MySQL Database
  • Request 5 most recent news items
  • Sort news items from most recent to oldest
  • Read a template file and substitute variables for content
  • Output the finished page to the user
Diagram of the page request

This takes a considerable amount of time, it's negligable if you get one or two visitors an hour, but if you get 500 visitors an hour it makes a big difference.

Consider the difference between this, and a straight forward request for a normal .html file. The web server doesnt have to do any hard work to serve up a .html file, it just finds the file and dumps it's contents to the browser... using caching allows you to experience this speed gain even with dynamic sites.

Continuing the same example, but where caching is in place, the first user to request the News page would cause the script to do exactly as above, and in addition actually increase the load by making it write the result to a file, as well as to the browser. However, subsequent requests would work something like this:

Diagram of the page request with a page cache

As you can see, the MySQL database and Templates aren't touched, the web server just sends back the contents of a plain .html file to the browser. The request is completed in a fraction of the time, the user gets their page faster, and your server has less load on it - everyone's happy.

 

Best Regards,

Lee

Quote · 20 Mar 2010
 
 
Below is the legacy version of the Boonex site, maintained for Dolphin.Pro 7.x support.
The new Dolphin solution is powered by UNA Community Management System.