[wp-hackers] Transient key best practice

Micky Hulse mickyhulse.lists at gmail.com
Mon Sep 9 20:39:23 UTC 2013

Hi Otto! Thanks for the help, I really appreciate! :)

On Mon, Sep 9, 2013 at 1:25 PM, Otto <otto at ottodestruct.com> wrote:
> It is a very bad idea to use mutating keys for transients. You run the
> risk of storing transients in ways such that you never actually try to
> get them again, thus creating lots and lots of entries in the database
> for those transients, for no reason.
> The important part of a caching mechanism is that you read from the
> cache. If your key is constantly changing in a way that makes doing
> this read less likely, then your cache isn't very useful, is it?

Thank you for pointing this out. I had a feeling that I might be going
a little overboard with my key names.

> I would absolutely not include cache time or number of items in the
> key, because these can change and then you'll never look up that
> cached data again, leaving it orphaned.

Sounds like good advice. I'll drop the number of items and cache time.

My thinking was that on one page, I might want to request a YouTube
playlist ID of XYZ that's 10 items total (the YT API lets you limit
the number of items it returns) and is cached for 30 minutes. On
another page I'd want to get the same playlist but with 20 items and
have that cached for 60 minutes.

I think I can live without that type of granular control though.
Thanks again for the helpful feedback, it's much appreciated! :)

Oh, I was also wondering about the automatic removal of transients
from the database ... Looks like Nikola's got that question covered.


More information about the wp-hackers mailing list