Last updated on

Database caching is a performance optimization that takes frequently made database queries and stores them in memory which reduces the amount of interactions between your site and your database. This helps improve your site’s response times and frees up more resources to accommodate more visitors and more traffic.

Database Cache Settings

Here we will review the Database Cache Settings section in W3 Total Cache for WordPress and examine what each of the available settings do.

General

Don’t cache queries for logged in users

Default value: Enabled
Enabling this option ensures that your site uses the default WordPress behavior and excludes logged-in users from the cache. Whenever a user is logged in to your website, their requests bypass the database cache entirely, meaning WordPress retrieves fresh data directly from the database for each query. Logged-in users might make changes to the website or their own data, such as post authors publishing updates on a post or a site member updating their profile. Caching this content could lead to inconsistencies or outdated information for other users. In most cases, the potential drawbacks of caching content for logged-in users outweigh the benefits, so leaving this setting enabled is generally recommended.

Advanced

Maximum lifetime of cache objects

Default value: 180 seconds

This setting determines how long cached data remains stored in memory before being considered outdated and refreshed. A longer lifetime improves performance by serving cached content quicker, reducing database queries and server load. However, too long a lifetime can lead to outdated data being served to users. On the other hand a shorter lifetime ensures users receive the latest data, but results in more frequent database queries and potentially slightly slower loading times.

Choosing the right value:

  • High-traffic sites: For websites with frequent updates and high traffic, a shorter lifetime is recommended to ensure data freshness. The default value is recommended for these sites.
  • Low-traffic sites: For less frequently updated sites with lower traffic, a longer lifetime (such as 7200 seconds) might be acceptable, balancing performance and freshness.

Garbage collection interval

Default value: 3600 seconds

This setting defines how often the plugin automatically scans and removes expired or outdated cached data from memory. This can be extremely important for ensuring users receive the latest information, even if the Maximum lifetime of cache objects setting allows a longer cache duration.

At the defined interval the plugin checks the timestamps of all cached objects in memory. Any objects that have exceeded their maximum lifetime or haven’t been accessed within a specific timeframe are identified as outdated. The outdated items are then removed from memory, freeing up space and ensuring future requests retrieve fresh information from the database.

Choosing the right interval:

  • Higher traffic sites: Websites with frequent updates and high traffic benefit from more frequent garbage collection (e.g., every 30 minutes) to ensure swift removal of outdated data.
  • Lower traffic sites: Less frequently updated sites with lower traffic can adopt longer intervals (e.g., once per day) while maintaining reasonable data freshness.

Never cache the following pages

Default value: null

This setting allows you to exclude specific pages or URLs from being stored in the database cache. This means those pages will always retrieve data directly from the database on every request. While the pages added to this list won’t get any of the performance benefits of the database cache, therefore it is recommended to use this sparingly or only when necessary. Pages with frequently changing content, like user accounts, shopping carts, or live updates, shouldn’t be cached to ensure users always see the latest information and updates.

Ignored query stems

Default value:

gdsr_
wp_rg_
_wp_session_
_wc_session_

This setting allows you to specify specific parts of database queries (known as “stems”) that should not be cached. In other words, queries containing these stems will always bypass the cache and retrieve data directly from the database, even if other parts of the query might be eligible for caching.

Some plugins rely on dynamic data that changes frequently or requires immediate interaction with the database. Caching queries containing these elements could lead to the visitor seeing outdated content on a page or discrepancies in information in something like a shopping cart. By ignoring specific stems, you ensure these elements always retrieve fresh data, circumventing potential caching-related issues.

Reject query words

Default value:

^\s*insert\b
^\s*delete\b
^\s*update\b
^\s*replace\b
^\s*create\b
^\s*alter\b
^\s*show\b
^\s*set\b
\bautoload\s+=\s+'yes'
\bsql_calc_found_rows\b
\bfound_rows\(\)

Unlike Ignored query stems which excludes entire query beginnings, this setting allows you to block caching based on specific words or patterns appearing anywhere within the query. Any query containing these words, regardless of context or surrounding elements, will bypass the cache and retrieve data directly from the database.

This can be helpful for things like preventing caching of search results pages to ensure users always see the latest results. Or if a plugin uses specific keywords in its queries, you can exclude them from caching while allowing other functionalities to benefit from caching.

Reject constants

Default value:

APP_REQUEST
DOING_CRON
DONOTCACHEDB
SHORTINIT
XMLRPC_REQUEST

This setting prevents caching of any query containing specific constant values defined by you. The constant value could be a number, a string of text, or other data included directly within the query itself. While other settings target query structure or keywords, this setting focuses on specific data values.

W3 Total Cache

You haven't seen fast until you've tried PRO

   Full Site CDN + Additional Caching Options
   Advanced Caching Statistics, Purge Logs and More

Everything you need to scale your WordPress Website and improve your PageSpeed.

Leave a Reply

Your email address will not be published. Required fields are marked *

W3 Total Cache logo

We Can Help Optimize Your Website

Optimize your site’s performance with our one-time premium services or ongoing monthly VIP support. View services

Partners

Bunny CDN Logo