22 votes
Accepted

Is get_option() faster than accessing get_transient()?

The TLDR: For 99% of people they're the same thing and just as fast as each other. This is micro-optimisation and not worth your time. Today I run a test over my db to explore the speed difference ...
Tom J Nowell's user avatar
  • 59.2k
11 votes
Accepted

Why are transients cleared prematurely?

TL;DR Wordpress part of transient handling is solid, everything is pretty precise Transients use object cache instead of data store for non-default implementations It means that some back-end cache ...
N00b's user avatar
  • 2,169
11 votes
Accepted

How to make sure that only one wp_cron() runs at a time?

Yes, it is possible... And to be honest, it's often very important to do this... WP Scheduler sometimes tends to cause problems, when cron tasks are long... So how I solve this problem? I use ...
Krzysiek Dróżdż's user avatar
9 votes
Accepted

Does using set_transient() function can lead to MySQL problems?

Does using set_transient() function can lead to MySQL problems? No, although if you used it so much that the MySQL server ran out of disk space, then yes it could cause issues. However, you would ...
Tom J Nowell's user avatar
  • 59.2k
9 votes
Accepted

Do WordPress' cron's clean up expired transients?

Yes, delete_expired_transients is a cron event that runs once per day and the function delete_expired_transients() is automatically called when the cron event runs — see wp-includes/default-filters....
Sally CJ's user avatar
  • 39.1k
7 votes

how to get the value of time left for a transient

The problem here is that if the site is actually using something like Redis, or any other supported "external cache" then nothing is going to actually be set in the options table (which can be checked ...
sMyles's user avatar
  • 2,836
6 votes
Accepted

Why does WordPress create two transients with the same name when I specify timeout value?

Why WordPress creates two transients: Because the first transient with timeout in the name, is used for storing the expiration you set for your transient (but the stored value is a UNIX timestamp, not ...
Sally CJ's user avatar
  • 39.1k
5 votes

Wordpress transients for a shortcode

I add it the transient name to a variable to handle it easier. Next, I check if the return value from the get_transient is false and update the variable name and the transient. You can try this one: ...
Drupalizeme's user avatar
  • 1,606
5 votes

Is get_option() faster than accessing get_transient()?

If no object caching is found, get_transient calls get_option twice, once or the expiry interval and one for the value, therefor it is not going to be faster. get_option performance by itself will be ...
Mark Kaplun's user avatar
  • 23.4k
4 votes
Accepted

Can set_transient() be used in multi-site?

As the Codex suggests: Essentially the same as set_transient() but works network wide when using WP Multisite. One difference is that the transient name should be 40 characters or less in length. ...
The J's user avatar
  • 562
4 votes
Accepted

Wordpress transients for a shortcode

Use this instead of the line in wich you define $days (your second line): $transient = get_transient( 'your_transient_key' ); if( !$transient ): $days = file_get_contents( 'json_file' ); ...
GDY's user avatar
  • 428
4 votes

wp_transients | wp_object_cache VS SESSIONS & Cookies?

set_transient() using wp_cache_set() and mysql database. WP Cache API using $GLOBAL(global session for application). Cookies and Session saves data only for one current user(cookies in browser, ...
Igor Sorish's user avatar
4 votes
Accepted

Difference between get_site_transient() and get_transient()

get_site_transient() uses the older nomenclature for multisite which referred to a multisite network as a "site" and individual sites on the network as "blogs". So ...
Jacob Peattie's user avatar
3 votes
Accepted

Use Transient API to cache queries for all posts in all categories?

You're saving every query object for each category to the same transient. Because this happens fast and time frame is one day, you're always getting the query object for the first category back. Make ...
Nicolai Grossherr's user avatar
3 votes

What's the case against transient-ing almost everything that's mostly static?

Actually, doing it for menu is good, you can even store entire HTML output and cut not only queries, but processing time too. Additionally, you can use WP_Object_Cache directly in conjunction with ...
Ihor Vorotnov's user avatar
3 votes
Accepted

How many transients is too many transients

It depends if you add an expiration time. If you do not add an expiration time then autoload will be yes. This means the option that stores this transient will be loaded on every request even if it's ...
Tom J Nowell's user avatar
  • 59.2k
3 votes
Accepted

What is the best way to cache pages and queries in WordPress?

No, there isn't. WordPress does not provide page caching mechanisms, and has no APIs for it. There is no generic way to say example.com/page is now stale and needs recreating. Nor is there any generic ...
Tom J Nowell's user avatar
  • 59.2k
3 votes

What is the best way to cache pages and queries in WordPress?

Ignoring some of the unique case details you provided, server-level page caching and object caching is nearly always the most efficient combination in terms of resource usage and scaling. Specifically,...
Jesse Nickles's user avatar
3 votes
Accepted

How can I stop my WordPress database collecting transients such as RSS feeds in wp_options table?

but I'd like to know if there is a way to prevent them from getting into my database in the first place. The only way to prevent expired transients ever being a thing is to never use them to begin ...
Tom J Nowell's user avatar
  • 59.2k
3 votes
Accepted

What would cause set_transient() and set_site_transient() to fail silently?

If you have a persistent object cache setup, then transients will not write to the database: they'll be stored in memory. Reviewing the definition of set_transient() this can be seen: if ( ...
Caleb's user avatar
  • 1,773
2 votes

Reset Transient on New Day

There is no reliable way to achieve what you want with the Transients API - or even, if you have been considering it, with the WP Cron system. The problem is in a nutshell: Those API systems depend on ...
Nicolai Grossherr's user avatar
2 votes

Reset all transients on post or page save

The technical side of it depends on the storage used. For default database storage the transient entries can be queried and deleted, since they have specific naming format. For enabled Object Cache ...
Rarst's user avatar
  • 99.7k
2 votes

how to get the value of time left for a transient

There is no built-in WordPress function to get the transient timeout. But you can use the following function to get the transient timeout. function get_transient_timeout( $transient ) { global $...
Nathan Johnson's user avatar
2 votes
Accepted

Using transient for dynamic css , how to name it?

Unless you do something weird with your settings, transients will just make your code harder to read without adding any measurable performance value. People that want performance should use object ...
Mark Kaplun's user avatar
  • 23.4k
2 votes

Clearing cached plugin data if it is using an external object cache

We note that the Transients API uses the Object Cache API, when we use an object-cache.php drop-in file. For example if wp_using_ext_object_cache() returns true, then get_transient( $transient ) -&...
birgire's user avatar
  • 67.1k
2 votes
Accepted

What to use , set_transient, set_option or file system?

I would go with transient. The reason I would choose transient it is they are created exactly for your case. I know that you have your own removal functionality but why to repeat yourself? Another ...
kierzniak's user avatar
  • 2,432
2 votes
Accepted

How do I reset a transient when updating a widget's value?

The simplest thing to do is simply delete the transient when the username is updated. Then the next time get_json() is run it will see that the transient is not set, just as if it had expired, and ...
Jacob Peattie's user avatar
2 votes
Accepted

Synchronize Data every minute with set_transient

To my understanding, *_transient() is basically *_option() wrapped in a cache-timer. What that means in this context, is that set_transient( '...', true, * MINUTE_IN_SECONDS ); will not run/re-...
David Sword's user avatar
  • 3,327
2 votes

What is the best practice to set and update Transient value of API data in every minute?

There is no way to do that. You need to design a push solution instead of a pull one, and if you can't and must have to use pull.... well than it sucks to be you :(. Web servers and web software is ...
Mark Kaplun's user avatar
  • 23.4k
2 votes
Accepted

WordPress transient doesn't use the transient

I mean in shortly your code is wrong in the first line, the comparing is wrong. The variable $post should store = the data of the request via get_transient() and not compare ===. So you should switch ...
bueltge's user avatar
  • 17.1k

Only top scored, non community-wiki answers of a minimum length are eligible