A number of my WordPress plugins make use of transients to cache data. However, I’ve had a number of people – mainly relating to Artiss YouTube Embed – highlight the large number of entries this is creating in their Options table. In the case of that plugin I implemented an option that allowed you to clear old transients down and even list the number stored.

Today I had a chance to investigate it further and found a large number of transients that had expired still in my Options table.

So I did what any good WordPress developer would do – went staight to “the horses mouth”. In this case, WordPress Core developer Andrew Nacin.

He confirmed my suspicions – that WordPress doesn’t housekeep transients unless you attempt to access them and they’ve expired. In other words, if you don’t access it then the expired transient remains. In the case of YouTube Embed the transient name is based upon the video parameters – so if you change an option it will generate a new transient name (as it should – you want the video code to update if you’ve changed one of the parameters). Unfortunately, the previous one is no longer accessed and, hence, never gets deleted.

Thankfully, there is hope on the horizon – a WordPress ticket is already open to add better housekeeping and Andrew has asked me to nudge him in January so that he can get it included in WordPress 3.6. I’ll certainly be doing that.

Update 1

Rather than be patient and wait for the change I have, instead, created a plugin that will do exactly what was proposed in the aforementioned ticket. I’ve also taken an opportunity to improve on it further by optimising the Options table each time housekeeping is performed.