1

I have a page that displays a random post every day. In order to change post every 24 hours I use

set_transient('totd_trans_post_id', $totd[0]->ID, (60*60*24));

What I'm wondering is this:

  • Does the countdown (60*60*24) start as soon as I have inserted and saved the code?
  • If yes: What happens if I let the code run for 23 hours, and then decide to "update" the code. Will the countdown restart?
  • If no one visits the site for 48 hours, will the expiration still take place? Or does someone have to visit after 24 hours to "run" it?
  • For a nice rundown on how transients are implemented (and why they may or may not be destroyed at any given time), read A Technical Transients Treatise on the WP Engine blog. – webaware Feb 3 '14 at 9:10
3
  1. The countdown would start as soon as the transient is created or updated.

  2. Running set_transient() on an existing transient value will restart the clock. Per the Codex page on set_transient():

    If a transient exists, this function will update the transient's expiration time.

  3. According to the Transients API page, the expiration time is the maximum lifetime of a transient value. It may be deleted before the time is up, but it will never return its value after the time is up:

    Transients may expire before the $expiration (Due to External Object Caches, or database upgrades) but will never return their value past $expiration.

3

Just to add to @pat's answer, There is no countdown, The time value represent the maximum amount of time for which the value being stored will be considered "fresh", and after that time it will become "stale" and ignored. There is no active countdown and no active purging from the DB/memory. This might sound like semantics but it might become important if you generated many transients as they will not clear themself automatically from the DB.

  • That complicated things.. Are the transient values stored in the WP_option table? – Tony Fire Jan 24 '14 at 12:33
  • Depends, they are stored there if there is no object caching active. If caching is active they are stored only at the cache (which means they might expire much sooner then you plan depending on cache purging policies) – Mark Kaplun Jan 24 '14 at 18:10
  • Well, I'm using W3 Total Cache, would that conflict with the transients? – Tony Fire Jan 28 '14 at 17:50
  • 2
    no, no reason it will happen – Mark Kaplun Jan 29 '14 at 7:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.