2

I noticed that some transients on my site every now and then go from having an expiration date to "Does Not Expire". I have noticed this happening with some plugins (eg Gravity Forms) but also happening to transients I created. Any ideas?

UPDATE: I am not sure how Gravity Forms sets and retrieves their transients but I was just using the examples from the codex

//Set transient name based on post tags being used
$transient = 'rest-posts-' . md5(serialize($tags));
if (false === ($data = get_transient($transient))) {
    //Run query here and then set transient
    set_transient($transient, $data,24 * HOUR_IN_SECONDS);
}

This works... meaning, if no valid transient then it will create one. However, every now and then I see the data is not updating, and so I check all my transients and noticed that some changed status to "Does Not Expire". No new transients are created once the current ones are set to "Does Not Expire". I am using a transient plugin to manage all transients. So once I delete the transients with "Does Not Expire" status, then new ones are created just fine.

1
  • 1
    To add to @rarst's answer, it is just impossible to know why things work in your setup "that way". You most likely have some code or plugin that somehow makes transients to misbehave. In any case from your snippet you use transients for something they should probably not be used for as there are better ways to achieve it. Dec 21, 2015 at 17:21

1 Answer 1

3

Transients do not expire if expiration time is not provided. Note that you can inadvertently cause this if you provide zero value for the time.

You should be aware that this still doesn't guarantee transient will stay alive. That's shouldn't be relied on.

As a core implementation detail it will delete all database transients on database version upgrades. That has been implemented while back to address the issues with possibility of database getting clogged with enormous amounts of old transients.

6
  • This is informative, but it does not tell me why transients on my site are being set to "Does not expire" for no apparent reason. I have transients set to expire in 24 hours and Gravity Forms has transients set to expire in 2 minutes... and sometimes both of these transients change status to "Does not expire" which is not the same as "Expired".
    – gdaniel
    Dec 21, 2015 at 15:20
  • It does — they don't expire if they don't have explicit expiration time. Why don't they have explicit expiration time is completely up to code which creates them.
    – Rarst
    Dec 21, 2015 at 15:21
  • What do you mean? Is 24 hours not a specific expiration date?
    – gdaniel
    Dec 21, 2015 at 15:26
  • I had jumped over part of your comment a bit. If you have transients that have expiration time and loose it — that would be extremely strange. What exactly are you using to get "Does Not Expire" result?
    – Rarst
    Dec 21, 2015 at 16:01
  • I updated my answer with some code.
    – gdaniel
    Dec 21, 2015 at 17:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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