Different caching mechanisms compared

Opcache vs CDN vs Page Cache

Cachcing the request using either apache cache, page cache, CDN cache, Opcache : and finding the best option

    Caching web request to improve performance

    Different caching and speed improvement mechanisms are deployed by web development companies across the globe to get their clients website load faster. While many of the web developers straight away go to using page cache for improving the website speed, a cached page only works for sites that do not serve dynamic content to users. Even in cases where page cache is not the best option, companies go ahead with it and set rules to clear cache frequently to get around the issue. But with other options available reduce the server load and improve page serving performance, let’s discuss those options and how well they fit for different use cases.

    Best Caching Opcache Cdn Apache Page Browser Cache

    Different caching options and what is the deciding factor

    Without wasting much of your precious time, lets dive in talking about the popular options and how each one of them compares to the other.

    Browser Cache

    Caching resources using browser is an efficient and is a recommended way to go ahead with. While browser cache is commonly used to cache static resources such as images, css, js and font files, there is a rare chance that the browser cache of some dynamically generated js may break some functionality. It is advised to enable this functionality by default for all the static files and selectively excluding the static files that may throw error while being cached. Nothing much to talk here as this is a browser side cache and can be cleared by the user on their end by clearing browser history.

    Page Cache

    Page caching is done by the website software, a CMS such as wordpress or joomla have inbuilt caching mechanisms that allow caching output of PHP and storing it as a static file, thus serving from the cache for subsequent requests. This cache is extremely fast and allows reducing server resource usage down by almost 95%. While extremely speedy, this cache may cause some website not to be able to function correctly. If there are some dynamic components such as shopping carts, polls, POST request that require content to change based on input, a failure may occur. For such a system, either complete re-design of those components to load via ajax is required, or we need to use other caching solutions.

    Zend Opcache

    Opcache is a server  level cache, and it compiles PHP and stores the compiled version of the code in the memory. Any web application built using PHP can take advantage of this type of cache. This method allows servers to save on processing power, by not loading every code request from the disk but instead load the compiled version from RAM thus saving on IO and processing power. This allow a server to run smoother and deliver faster results on the frontend. The only disadvantage of this cache system is from the development prospective. If there is a file change, and opcache setting are not configured to instantly recognize the change, the results of the code change may be delayed thus causing issues with the web development process. Only advise here is to keep opcache disabled in dev environments.

    CDN Cache

    CDNs also cache resources on their end to allow faster content delivery. CDN providers such as cloudflare allow you to use page rules using which you can set separate rules for different types of resources. For example, you can set all images to be cached by the CDN and put a long expiry of the cache. Not only the image resources will be delivered faster, you will also save on bandwidth costs. A perfect setup for a regular website would be cache all style-sheets & java-script files, images and fonts, skipping caching of html page. Also, some CDNs provide security features that protect websites from DDOS and other attacks. Some also come with firewall that allows you to setup rules such as blocking a complete country or IP range.

    We have discussed some popular caching mechanism used in the industry and we hope this help to clear some doubts. If you have any query or need us to look into your website issues, let us know. We are masters of web development and help our clients to improve their websites.