What does the WP_CACHE constant do?
The WP_CACHE constant in WordPress plays a crucial role in website performance. It tells WordPress to load a page cache drop-in, which can significantly improve the speed and efficiency of your site.
The WP_CACHE constant is defined in the wp-config.php file, which is located in the root directory of your WordPress installation. By default, this constant is not set, meaning caching is disabled. You can enable it by adding the following line to your wp-config.php file:
define( 'WP_CACHE', true );When you set WP_CACHE to true, WordPress loads the file wp-content/advanced-cache.php early on every request. Caching plugins put their page cache in that file: it stores a static version of your pages and posts. Without a caching plugin that provides the file, the constant does nothing.
As a result, when a visitor requests a page, WordPress can serve the cached version instead of querying the database and processing PHP scripts each time.
Benefits of enabling WP_CACHE
Section titled “Benefits of enabling WP_CACHE”Let’s dive deeper into what the WP_CACHE constant does and how it can benefit your WordPress site.
- Improved Load Times: With caching enabled, your site can deliver pages faster. This reduces load times, enhancing the user experience.
- Reduced Server Load: Caching decreases the number of database queries and PHP executions. As a result, your server can handle more visitors simultaneously.
- Cost-Effective: If you’re using a hosting plan with limited resources, caching can help you utilize those resources more efficiently.
When to use WP_CACHE
Section titled “When to use WP_CACHE”We generally encourage all WordPress sites to have cache turned on, but most certainly when:
- Your site experiences high traffic.
- You notice slow page load times.
- You’re running a resource-intensive WordPress site.
There’s a plugin for that
Section titled “There’s a plugin for that”Manually adding the WP_CACHE constant to your wp-config.php file is not always the best approach. There are several WordPress plugins that turn on cache for you, making the process seamless and error-free.
Some popular caching plugins are:
In Scanfully
Section titled “In Scanfully”The Site health screen shows the constant under Details, as Cache drop-in (WP_CACHE): Enabled or Not enabled. Scanfully does not raise an issue for it either way.
