[wp-hackers] using transient api with http api

fris fris at fris.net
Tue Aug 2 00:13:12 UTC 2011


Would the json decode be in the if statement? Just a line before set
transient, or do you mean before the if?

Cause the response is coming from the http api in the if statement.

-----Original Message-----
From: wp-hackers-bounces at lists.automattic.com
[mailto:wp-hackers-bounces at lists.automattic.com] On Behalf Of Otto
Sent: Monday, August 01, 2011 5:53 PM
To: wp-hackers at lists.automattic.com
Subject: Re: [wp-hackers] using transient api with http api

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
>
_______________________________________________
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