[wp-hackers] how big objects can i cache using wp transient api?

peter baylies pbaylies at gmail.com
Mon Oct 3 17:58:51 UTC 2011


You snipped the part where the results get cached; in regular usage, that
SQL query shouldn't get executed again on subsequent calls to
wp_load_alloptions() so I wouldn't worry about it too much.

 -- Peter

On Mon, Oct 3, 2011 at 7:03 AM, Phillip Lord
<phillip.lord at newcastle.ac.uk>wrote:

>
> I have been worrying about this also.
>
> I may have this wrong, but looking at the back end implementation,
> transients appears to back on directly to the options API. Now at times,
> this calls "wp_load_alloptions()"
>
>
> function get_transient( $transient ) {
>      // ....snip
>
>                        // If option is not in alloptions, it is not
> autoloaded and thus has a timeout
>                        $alloptions = wp_load_alloptions();
>      // .... snip
> }
>
> which in turn looks like this...
>
>
> function wp_load_alloptions() {
>              // ....snip
>
>                if ( !$alloptions_db = $wpdb->get_results( "SELECT
> option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" ) )
>                        $alloptions_db = $wpdb->get_results( "SELECT
> option_name, option_value FROM $wpdb->options" );
>              // ....snip
> }
>
>
> So, it seems to me, that extensive use of the transients API with big
> things is going to come with a substantial performance problem.
> Potentially, this will affect not just "get_transient" calls but also
> anything that results in wp_load_alloptions() being called.
>
> The reason I mention this, is I have tried putting a reasonable amount
> of stuff (100's of records, although not individually large) into
> transients. I also appear to be getting some memory issues, and I am a
> bit suspicious that this is transients, but haven't had time to
> investigate really heavily.
>
> I was thinking of rewriting the entire thing as a custom post type,
> although this seems a pity as the transients API otherwise does (nearly)
> what I need.
>
> Am I barking up the wrong tree here? Have I totally misunderstood the
> implementation?
>
> Phil
>
>
> Otto <otto at ottodestruct.com> writes:
> > The option_value is longtext, which has a maximum size of 2^32-1
> > (4,294,967,295) characters.
> >
> > In practical terms, the limit will be lower, but there's no particular
> > issue with storing large data values in a transient. You may have
> > speed issues in retrieving something that large from the database very
> > often though. I'd suggest evaluating what parts of the data you
> > actually need to use and store only those. If you're using the whole
> > thing, then maybe another approach would work better, such as storing
> > it in a custom post type.
> >
> > -Otto
> >
> >
> >
> > On Fri, Sep 30, 2011 at 5:41 AM, Konrad Karpieszuk
> > <kkarpieszuk at gmail.com> wrote:
> >> hello
> >>
> >> i cannnot find answer for this question. i have quite huge array which
> >> i want to remember in transient. this array after serialization has
> >> lenght over 300000 signs ( i check this using
> >> strlen(serialize($my_array))
> >>
> >> will it be a problem for transient api?
> >>
> >> --
> >> (en) regards / (pl) pozdrawiam
> >> Konrad Karpieszuk
> >> _______________________________________________
> >> wp-hackers mailing list
> >> wp-hackers at lists.automattic.com
> >> http://lists.automattic.com/mailman/listinfo/wp-hackers
> >>
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
> >
>
> --
> Phillip Lord,                           Phone: +44 (0) 191 222 7827
> Lecturer in Bioinformatics,             Email:
> phillip.lord at newcastle.ac.uk
> School of Computing Science,
> http://homepages.cs.ncl.ac.uk/phillip.lord
> Room 914 Claremont Tower,               skype: russet_apples
> Newcastle University,                   msn: msn at russet.org.uk
> NE1 7RU                                 twitter: phillord
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list