Site AI Auditpar Internet Solutions

WordPress Transients: When Cached Data Slows the Database

29 octobre 20268 min de lectureVitesse du site
WordPress Transients: When Cached Data Slows the Database

Short answer: A transient is a piece of temporary data that WordPress or a plugin stores for a limited time, such as the result of a slow request to another service. By default transients live in the database, in the same options table as your settings. When thousands of them pile up, or when they have no expiry date, they can slow the database and every page that depends on it. A persistent object cache moves them out of the database, and a careful cleanup keeps the rest under control.

What a transient is

Many things on a WordPress site are slow to produce: a call to a weather or shipping service, a complex query that counts products, a feed from a social network. Running that work on every visit would be wasteful, so plugins save the result for a while and reuse it. WordPress provides a simple tool for this, called the Transients API.

A developer stores a value with a name and an expiry time, for example “keep this for one hour”. On the next visit, the code first looks for the stored value. If it is still there, it is used. If it has expired, the work is done again and the new result is stored. This is a form of caching, a close relative of the techniques in page caching, but on a smaller scale and at the data level.

Where transients are stored

This is the part that matters for speed. The storage depends on your setup.

Most small sites on ordinary hosting do not have a persistent object cache, so their transients live in the database. That is perfectly normal for a few dozen of them. The trouble starts when the number grows without limit.

How transients slow a site down

  1. Transients without an expiry are autoloaded. When a transient is saved with no expiration time, WordPress loads it into memory on every request, together with the other autoloaded options. A few large values of this kind add weight to every single page view. This is the same hidden cost described in autoloaded options.
  2. Large values. Some plugins store whole API responses, long lists or rendered HTML. Reading and writing large rows takes time, and it increases the size of the database and its backups.
  3. Too many unique names. If a plugin creates a new transient name for each visitor, search term or product filter, rows accumulate quickly. Hundreds of thousands of rows make queries on the options table slower.
  4. Expired rows that stay. Expired transients are removed when they are requested again, and WordPress also runs a periodic cleanup. But a transient that is never requested again can remain until that cleanup runs, and a stalled scheduled task, see WP-Cron and performance, delays it further.
  5. Cache stampedes. When a popular transient expires, several visitors can try to rebuild it at the same moment. If rebuilding is slow, the server can briefly become overloaded.

A real-life example shows the pattern. A small shop installs a plugin that shows delivery estimates. For every product and every postcode a visitor tries, the plugin stores a new transient with the answer. After a few months, the options table holds many thousands of rows that nobody will ever read again, and the admin area, which loads options constantly, feels sluggish. Nothing is broken in the usual sense: each transient did what it was designed to do. The damage comes from volume and from the lack of limits, which is why monitoring matters more than any single setting.

How to see whether transients are a problem

You do not need to guess. A few checks give a clear picture.

Work on a staging copy or take a full backup first. See the website backup strategy guide for a safe approach.

Safe cleanup

Expired transients are, by definition, no longer needed, so deleting them is low risk. Transients that have not yet expired are being used by something, so remove them only when you understand why.

  1. Take a backup of the database.
  2. Delete expired transients, using a reputable cleanup or database optimisation plugin or a command-line tool. Many hosts and database tools include this action.
  3. Check the site, especially the pages and features that rely on external data. If a plugin has to rebuild a transient, the first visit after cleanup may be a little slower.
  4. If the number of rows grows back quickly, find the plugin that creates them. Updating, replacing or reconfiguring it solves the cause, while cleanup only treats the symptom. See how to find which plugin is slowing your site.

The broader routine in WordPress database cleanup covers other safe steps, such as removing post revisions and spam comments.

Better long-term fixes

A note for developers

If you write code for your own site, set an expiry every time you create a transient, even if it is long, so that it is never autoloaded by accident. Give each transient a clear, limited name, and delete it when the related content changes. Do not use transients to store data that you cannot afford to lose, because they can disappear at any time, for example when a cache is flushed or a database cleanup runs. For permanent data, use real options, post meta or your own table.

If your host offers a staging tool and a database size report, use them as an early warning. An options table that grows steadily month after month, with no new content to explain it, is usually the sign of a plugin that stores temporary data without limits. Catching that after a few weeks is much easier than discovering it after a few years, when cleanup becomes a nervous, large operation.

How Site AI Audit helps

Site AI Audit does not look inside your database, so it cannot count transients. It measures what visitors feel when a database is slow: server response time, Google PageSpeed results for mobile, Core Web Vitals, compression and page weight, plus the SEO, SSL, security header and e-mail checks around them. The first check is free, covers up to 50 pages and needs no sign-up. You can run a free check of your website or see the plans for weekly monitoring.

Related reading

The bottom line

Transients are a useful, built-in way to cache temporary data, but they live in your database unless you have an object cache, and unmanaged ones can grow into a drag on every page. Check how many you have and how large they are, clean up expired rows after a backup, find the plugin that creates too many, and move to a persistent object cache if your host offers one. A small amount of tidiness keeps the database quick and the pages responsive.

FAQ

Is it safe to delete all transients?

Expired ones are safe to remove. Active ones will usually be rebuilt on demand, but a plugin may be briefly slower while it does so. Take a backup first and test the site afterwards.

Why do transients keep coming back after I delete them?

Because a plugin or theme creates them as part of normal operation. Deleting them only clears the current rows. Fix the cause by adjusting or replacing the plugin that creates too many.

Do transients affect SEO?

Not directly. Indirectly, a slow database raises server response time, which can hurt speed and user experience, and speed is one of many signals that search engines consider.

Do I need Redis to fix transient problems?

No. Many sites run well without it. A persistent object cache is helpful when the database is under heavy load or when many transients are in use, but cleanup and a better plugin can be enough.

What is the difference between a transient and an autoloaded option?

An option is permanent data that WordPress can load on every request. A transient is temporary data with an expiry. A transient saved without an expiry behaves like an autoloaded option, which is why it can slow every page.

#Caching#Page speed#WordPress performance
Vérifiez votre propre site — gratuitement.Ce qu’il faut corriger sur votre site — et par où commencer.
Commencer gratuitement

Plus d’articles du blog

Tous les articles →
Internet Solutions

Plus de notre équipe

Conçus par Internet Solutions. Découvrez nos autres produits — chacun vous fait gagner du temps à sa manière.

internet-solutions.net ↗