[wp-hackers] using transient api with http api

Otto otto at ottodestruct.com
Mon Aug 1 21:53:19 UTC 2011


It's fine, but I would move the json_decode up before the
set_transient, so that you're storing the already decoded data instead
of the raw response from the other server. This saves you some time
and space in that you don't have to decode it every time.

Best to store just what you need in the transient, already processed
and ready to use. Faster that way.

Also, you can save yourself a few lines of code by using this pattern:

if ( false === ( $data = get_transient( 'whatever' ) ) ) {
 ...
 set_transient( 'whatever', $data, $timeout );
}

The first line in the if statement both gets the data and checks it
against false. This works because the result of an assignment is the
value that was assigned.

-Otto



On Mon, Aug 1, 2011 at 4:44 PM, fris <fris at fris.net> wrote:
> On using the transient cache with http api would this be correct?
>
> http://pastebin.com/B8XakNef
>
>
>
> _______________________________________________
> 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