[wp-hackers] transients API and removing stored results
phillip.lord at newcastle.ac.uk
Thu Mar 3 12:45:25 UTC 2011
I've been investigating the transients API for use with a plugin called
kcite (http://knowledgeblog.org/kcite-plugin/). The idea is to enable
the use of wordpress within an academic environment, by building
reference lists (reference as in "another piece of writing related to
this one"). References are dropped in using identifiers such as DOI,
Pubmed IDs bundled as shortcodes; these are then resolved through an
external service, which returns full metadata. After that, there is some
XML->HTML munging that isn't very interesting, but produces a nice
I've added in support for the transients API; each reference requires
between 1 and 3 HTTP requests to resolve, and with, say, 150 references
in a single post this can be problematic. The resolved references rarely
change, so setting up an expiry of a month seems reasonable; on the
other hand, failed requests might expire after 30 mins, while requests
that succeed by don't recognise the identifier might last 2 hours.
All of this is working well, but there is a problem. It's a development
nightmare. There's lots of stuff in the database now that persists, and
it's very hard to get back to a "clean" state. While I know the form of
all the slugs used for the transients
("kcite_identifier_source_identifier" -- all the ids are unique by
definition), I don't know all the slugs unless I parse all the posts, or
do something traumatic and messy like store all the slugs as the value
of another transient, with a single slug.
So, my question, is it possible to delete_transients based on a
wildcard? I could do this with a database query, but as the codex says
"don't assume your transients are in the database". I would like to be
able to add a "clear cache" function to the admin page for this plugin.
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. And, finally, the plugin identifies itself to the
resolution services; I don't the plugin to get blocked because people
don't follow a "don't use the plugin unless you are also using wp-cache"
Thanks in advance for any help.
More information about the wp-hackers