wp query - Using Transients

admin2025-04-19  1

I am new to the transient concept. But I am not sure about the efficient method to use it. I really liked it as it removed the duplicate queries that I had.

  1. I have set set_transient( 'pgggo_acf_list_transient', $pgggo_qry, 12 * 7000 ); is that too high?
  2. What if there is an admin update on the WordPress site and query that was set transient is modified. Will it get automatically updated?
  3. Where should I not use transient?

I am new to the transient concept. But I am not sure about the efficient method to use it. I really liked it as it removed the duplicate queries that I had.

  1. I have set set_transient( 'pgggo_acf_list_transient', $pgggo_qry, 12 * 7000 ); is that too high?
  2. What if there is an admin update on the WordPress site and query that was set transient is modified. Will it get automatically updated?
  3. Where should I not use transient?
Share Improve this question asked Nov 11, 2019 at 10:48 user145078user145078
Add a comment  | 

1 Answer 1

Reset to default 1

I have set set_transient( 'pgggo_acf_list_transient', $pgggo_qry, 12 * 7000 ); is that too high?

12 * 7000 is just over 23 hours. Whether or not that's too high (or low) depends entirely on your specific needs. The expiry time should be based on how often the data needs to be refreshed.

What if there is an admin update on the WordPress site and query that was set transient is modified. Will it get automatically updated?

No. That's the point of transients.

Where should I not use transient?

When you don't want the data to persist over multiple requests (page loads), over a span of hours, days or longer.


If you use a transient set to 23 hours to avoid making duplicate queries, it means the result of that query will be exactly the same for all users, for all requests, for 23 hours.

'Duplicate queries' is an issue where you are performing the same query multiple times during the same request. This is inefficient because the result of that query is not going to change during a single request. To prevent duplicate queries you should store the result of the query for the duration of the request in a variable so that you don't needlessly query the data again. The Object Cache API is designed for this.

Setting a transient saves the value to the database. You would only do this if you needed to store the data for longer periods of time. This is overkill for preventing duplicate queries, because you're not just preventing the query from being repeated during a request. You're preventing the query from being repeated for an entire day.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745014113a279985.html

最新回复(0)