How to Fix Caching Problems

10 Fixes for Caching Problems. And Why Caching Matters for Your WordPress Website

When you think about caching, what comes to mind? If your answer is “nothing” then this post is for you. If it seems like a scary, complex tech issue, then this post is for you too.

 

Many businesses often overlook the importance of caching and how it can be used to improve the performance of a website

 

In this guide we will explain caching, go over some common types of caching problems and discuss how to address them.

 

Ready? Let’s go…

 

What is Caching? And What is the Purpose of Caching?

Caching involves saving copies of files in a cache, or temporary storage location, so that they can be retrieved more quickly e.g. by downloading a website quickly. Effectively the content  is stored in a handy location so it doesn’t have to travel far across the web.

 

Websites are typically visited hundreds, thousands, or even millions of times each month. The server must perform a slew of complex (and time-consuming) computations whenever a browser requests a web page. It retrieves the most recent postings, creates the header and footer, locates your site’s navigation, sidebar widgets, and so on. Enter Caching. Caching makes the server remember the final result instead of having to go through this whole process from scratch each time you visit the same site.

 

Why Should I use Caching?

Caching data is crucial for optimising app performance and efficiency. It keeps data on your local device, so everything will appear quickly as you navigate through the pages on the site.

 

The benefits of Caching

There are a number of advantages to caching in WordPress. The fundamentals include:

  • It improves the speed and functionality of your website, which helps it to appear in the Google search results; speed is a ranking factor. Google loves faster websites. (Of course there are many factors and site speed is just one – but it’s an important one!)
  • Static cached files load faster than dynamic database queries which means improved performance and user experience – site visitors will not be put off by a slow experience.
  • Caching can help to reduce the load on your hosting server. This will save server memory and I/O operations. So caching is becoming more important, especially for those with limited hosting plans.
  • Apart from the UX, cached site means that the user’s bandwidth is also saved (albeit by a nominal margin), since static cached pages are smaller in terms of file size as compared to dynamic requests. Here’s the science bit – to have this happen, your caching solution must use combined and minified JavaScript and CSS in addition to basic page caching.

 

Types of WordPress Caching

In the world of wordpress – there are two distinct kinds of caching technologies depending on the client-server model:

1) Client-Side caching

2) Server-Side caching

 

Client-Side Caching

A website’s static data, such as pictures, CSS and Javascript files, is non-textual. Your browser is clever enough not to re-download these files when you press the F5 key. It simply retrieves data from the local cache i.e., the one stored on your computer’s hard drive.

 

This process of reusing the cached data from the client’s computer (or client’s end) is known as client-side caching and almost every modern website uses it and every browser supports it. Client-side caching saves server resources by preventing data redundancy (i.e. downloading the same data over and over again) and minimising data duplication (i.e. sending the same file to every user).

Server-Side Caching

Caching at the server is known as server-side caching. Server-side caching includes various caching protocols that are used e.g. for WordPress caching;

 

1) Page caching

2) Database query caching

3) Object based caching

4) Opcode caching

 

 

Page caching

This simply refers to keeping the dynamically created HTML files on the server’s hard drive or memory (RAM). It is also known as a cache. When a request is made, it will serve from the cache (i.e. reusing previously generated data) instead of executing PHP code and MySQL.

 

Database query caching

More resources will be required to run the databases. Databases are crucial for efficiently storing, updating, and distributing data. As they’re usually very large – each query takes time (usually in the order of a few hundred microseconds).

 

In the case of databases, the better the hardware – the faster the query result generation. Because WordPress is so reliant on its database, it makes numerous queries. It’s like re-downloading the same photos when data isn’t changed in the database and queries are made to retrieve the very same information.

 

In other words, saving the results of a query in the local storage will save time and resources. The end result of database queries’ results is local storage, which is known as database caching and this is one of the key components in WordPress caching. It’s necessary to delete and re-cache the database query results again when the database is updated, such as when a post is updated or published, or a comment is submitted.

Object based caching

WordPress has an internal caching system which includes several subsystems (i.e. the Caching API, Object Cache, and Transient API). The WordPress core allows plugins to control this caching system to reduce the number of database calls.

 

Opcode caching

Like the database caching, opcode caching refers to the saving of the compiled PHP code between every request. PHP is an object oriented programming language. To execute a PHP program, the PHP compiler must first compile the code and generate executable web server code.

Problems with Caching and Solutions

With all great technologies, there are often hiccups along the way. Let’s look at some of the most typical caching problems and how to address them.

 

Problems specific to individual user’s device

 

Web Browser Cache for Specific User

The most frequent caching problem is with a user’s web browser cache, which saves web files from previously viewed web pages on the local computer for quicker viewing of these sites in the future. The disadvantage of browser cache is that it may store out-of-date pages and associated files, such as CSS styles and JavaScript interactive scripts, causing unintended user experience. So basically the user is not seeing what they should be seeing on the site!

 

 

How to Identify:

The Issue is specific to a single computer that was previously used to visit the site in question, or multiple computers without any underlying similarities, such as a shared network.

Solution:

This can be resolved by clearing browser cache and restarting browser. Sometimes, even a simple hard refresh without restarting a browser would suffice.

 

User’s DNS Cache, Serving Old Page

DNS entries can be saved locally and this might cause difficulties during testing or web site launch. This is also contextual and depends on the users operating system.

How to Identify:

The problem is specific to a single computer that previously visited the website causing issues, or multiple computers on a shared network.

Solution:

Flush local DNS cache prior to viewing changes or during web site launch.

 

User’s Hosts File Pointing to Incorrect IP

A typical testing approach for a new site prior to going live is via changes in local hosts file. Hosts file allows creating a custom alias on a local machine between development URL (or IP address) and live domain name, so that the site in development can be viewed via a browser under its final domain name. Occasionally, the local hosts file entry is left after testing, which would prevent a specific user from seeing the live site since the domain name will continue to point to the development site, just as it did throughout testing.

How to Identify:

Problem is with a single computer that had its hosts file edited.

Solution:

Can be resolved by quick edit to hosts file.

 

Network-wide issues, to be addressed by network administrator

 

Caching on User’s Local Network

Network components, such as routers, can store cached DNS information.

How to Identify:

Issue will be common to all computers on a specific network.

Solution:

Turn off DNS caching or set dnsmasq to 0 names.

 

Caching on User’s Internet Connection Provider

Caching on internet provider side can occur if the provider uses proxy [server / router] for reducing external traffic.

How to Identify:

Users in one particular geographical region serviced by a specific provider will see this message. You can also use a service such as https://www.infobyip.com/detectproxy.php to see if your provider uses proxy [server / router].

Solution:

Contact the internet provider’s technical support and request specific web site (domain) to be either excluded from caching (included in do-not-cache list) or have its cached duration reduced to a bare minimum.

 

Web site issues, to be addressed by webmaster

 

Caching on Web Server, WordPress or Other Framework with build–in or modular Caching Feature

Memory-intensive frameworks can easily overwhelm a web server with just a few concurrent site visitors. To resolve this, many frameworks come with a caching feature that is either part of the core build or available as a module. When enabled, caching makes a compiled version of all scripts, pages and styles available for web site visitors, without making individual server calls for every code asset used to generate specific pages.

How to Identify:

Issue will appear on multiple computers without any underlying similarities.

Solution:

Framework cache can be cleared or turned off via CMS. But note that turning off framework caching is not recommended as it will severely impact the site’s performance.

 

Hosting-related issues, to be addressed by web server admins and hosting support


Caching by CDN (Content Delivery Network)

CDNs are used to reduce web server traffic and improve loading times for end user. The issue with CDN might be lack of synchronisation with hosting server that has the most recent files and content.

How to Identify:

Issue will be either geographically localised to one CDN serving specific region or widespread for multiple regions served by the same CDN provider. Can be identified by accessing web hosting server directly via IP and comparing content with that served via CDN.

Solution:

CDN provider’s IT needs to force refresh content from web hosting server.

 

Caching By Load Balancer for Server Cluster

Load balancer that directs traffic between multiple web hosting servers can have a caching feature configured and enabled.

How to Identify:

All users accessing site through load balancer will see incorrect cached content, but accessing web server directly by IP will show correct content (might require temporarily disabling load balancer).

Solution:

Server admin needs to either force refresh cache or reduce its duration.

 

Secondary Server not Synchronizing Content with Primary Server

When a primary server begins to reach its capacity, it mirrors its data to a secondary server, which can handle heavy web traffic when the primary server approaches its limits. If there’s an issue with mirroring files between servers, the secondary server will be serving different pages than primary server – even if content remains the same (for multi-server configuration, database will usually be handled on a separate server).

How to Identify:

Issue appears for random users during high volume web site traffic, as some users are directed to secondary server with outdated web pages.

Solution:

Restart and monitor mirroring process between two servers.

Upstream Caching by Hosting’s Broadband Provider

Caching of web files and DNS information can also occur at midpoints between user’s machine and hosting infrastructure.

How to Identify:

Depending on the number of upstream providers, the issue can be consistent for all users (in case of a single broadband provider) or random (in case of more than one provider). It can usually be identified by server and network administrator by accessing web site internally from the data centre network and getting a different result when accessing the same web site externally.

Solution:

Needs to be escalated by hosting provider to broadband provider’s tech support.

 

WordPress Plugins for Caching

 

Here are some more typical questions that we get about Caching:

Is Clearing Cache Bad?

In general, we recommend against clearing your Browser Cache unless there is a compelling need. The files in the cache make your favorite websites load faster, which is a positive thing. Because your browser periodically erases old files, the cache isn’t going to keep expanding indefinitely.

What is a caching in a computer?

Cache memory is a type of high-speed random access memory (RAM) which is built into the processor . Data can be transferred to and from cache memory more quickly than from RAM. Consequently, cache memory is used to temporarily hold data and instructions that the processor is likely to reuse.

Browser Cache

A cache of recently downloaded Web pages is kept in memory or on disk and is used to store the most frequently viewed material. When you hop from web page to web page, caching those sites in memory allows you to quickly return to a site without having to download it from the Internet again.

How do I empty the cache on my computer?

 

In Chrome

  1. On your computer, open Chrome.
  2. At the top right, click More .
  3. Click More tools  Clear browsing data.
  4. At the top, choose a time range. To delete everything, select All time.
  5. Next to “Cookies and other site data” and “Cached images and files,” check the boxes.
  6. Click Clear data.

Windows 10

You can clear cache or remove temporary files in your Windows settings:

  1. Click the Start menu (the Windows logo) in the lower left corner of your screen, then click the Settings icon.
  2. Click System.
  3. Click Storage.
  4. Click Free up space now.
  5. Wait for the scanning process to be complete.

 

Will Clearing cache delete pictures?

No, It will not delete any photos from your phone or computer.That action would require a deletion. What WILL happen is, the Data files that are stored Temporarily in your device’s Memory, thats the Only thing deleted once the cache is cleared.

When to use Caching database?

By distributing query workload to multiple cheap front-end systems, caching improves scalability by removing demand on the backend. It allows flexibility in the processing of data; for example, the data of Platinum customers can be cached while that of ordinary customers are not.

Where does dns caching occur?

DNS caching does not only occur at the OS and browser level. It is more complex as DNS lookup involves various steps. During a new DNS lookup, the lookup passes through the resolver, root server, and TLD server. At each step, information is gathered and cached for later use.

 

As you can see there is more to caching than meets the eye. But when used in the correct fashion – it can improve your website speed and performance dramatically! If you would like to know more web development – get in contact with us.