[wp-hackers] transients API and removing stored results

Casey Bisson casey.bisson at gmail.com
Thu Mar 3 13:26:39 UTC 2011

Nacin makes a good point, postmeta would be ideal for this but for the fact that one DOI can be referenced by many posts.

It may add more complexity than you want or need, but have you considered creating a custom post type to cache these lookups? It would make it relatively easy to delete all posts matching the given type, and you can leverage the taxonomy and postmeta tables to store detailed info about each reference.

The easy alternative is to just create a function that deletes all options rows where option_name LIKE {$transient_prefix}%, but that raises two less easy problems: it doesn't delete the relevant cache keys cases where memcache or some other persistent cache is in use, and it's probably not safe to assume that all those matched rows are in fact transients.

--Casey Bisson


On Mar 3, 2011, at 5:11 AM, Andrew Nacin wrote:

> On Thu, Mar 3, 2011 at 7:45 AM, Phillip Lord <phillip.lord at newcastle.ac.uk>wrote:
>> Incidentally, I went this route rather than wp-cache or equivalent for a
>> couple of reasons. As well as said earlier, different resolution
>> attempts need different expiration times. Second, the same identifier
>> can occur in several different posts; this way the data is shared
>> between posts. 
> I like the use of transients here. If I was doing this though, I probably
> wouldn't use them.
> One, I would cache this to postmeta instead of using transients. They're
> tied to posts, so it works from an implementation perspective. Assuming an
> object cache is leveraged, you're not even hitting the database, but note
> that postmeta is already queried for posts in the loop, so you're not really
> running into performance issues either.

More information about the wp-hackers mailing list