Is your website loading slow? Do you know majority of the visitors expect a website speed page load in 2 seconds or less…
So what can be done to help your website load faster and lower the load impact on the server? The answer is simple – make a cache of your website!
To understand why cache is necessary, one must first understand that how a dynamic page from a website is served. Firstly, when a request is made for the page or in a layman language a website is searched and clicked, then PHP generates that page while making database requests to generate the HTML output, which is then served to the visitor’s browser. If no caching is set up, then each time the request is made, the page is generated again and again thus increasing unnecessary server load and ultimately slowing the loading time of the page.
What caching does is that it stores the HTML output generated by the first request and then serves that output to the subsequent requests. This in turn eliminates or minimizes the need to call PHP or Database queries, which ultimately benefits in fast loading and reduced server load.
With caching enabled, the server can handle large number of requests with ease.
Web Caching can be broadly classified in two parts :
In Server side Cache, generally the output of the page is generated on the Server and the page is served from the Server. This can be further classified into 4 broad types:
Page cache is the most widely used server cache type, it is also the most efficient one. In this one, the cache of the whole page is generated and served to the visitor’s browser. Cached Page can be stored on Disk or in Memory. Serving cached pages from memory is faster than disk.
Object cache is used when only some elements needs to be cached on the page, this is useful if many of the page components are dynamic and needs to be refreshed multiple times, whereas some areas of page remains static, so they can be cached to improve performance.
Opcode cache is a powerful tool, it caches the result of PHP code compilation to bytecode. In layman terms, PHP is interpreter based language, i.e. in PHP each line of the code is converted to bytecode in runtime, but this happens every time a PHP script is invoked. When there are large number of requests, this causes a performance penalty. With Opcode cache this need is eliminated as the cache of complied code is already present in the server, which is then served, thereby reducing load.
With Database Cache, the most used database query results are cached in either Disk or Memory, so that the need for database calls is minimized. This in turn reduces database load since it only has to serve limited queries thereby increasing performance.
These are the basic highlights of web caching for a website which translates into faster load times and lower server load.