salcode.com/wcphilly19
Jump to resources
Website for a Computer
Website for a Computer
https://api.darksky.net/forecast/abc123/40.6,-75.4
$response = wp_remote_get( $url );
$body = wp_remote_retrieve_body($response);
$weather = json_decode( $body );
$temp = $weather->currently->temperature;
$response = wp_remote_get( $url );
$response = wp_remote_get( $url );
$body = wp_remote_retrieve_body($response);
$response = wp_remote_get( $url );
$body = wp_remote_retrieve_body($response);
$weather = json_decode( $body );
$response = wp_remote_get( $url );
$body = wp_remote_retrieve_body($response);
$weather = json_decode( $body );
$temp = $weather->currently->temperature;
$response = wp_remote_get( $url );
$body = wp_remote_retrieve_body($response);
$weather = json_decode( $body );
$temp = $weather->currently->temperature;
function fe_get_wp_temp_api_call() {
$response = wp_remote_get( $url );
$body = wp_remote_retrieve_body($response);
$weather = json_decode( $body );
$temp = $weather->currently->temperature;
return $temp;
}
function fe_get_wp_temp_api_call() {
// This is slow!
$response = wp_remote_get( $url );
$body = wp_remote_retrieve_body($response);
$weather = json_decode( $body );
$temp = $weather->currently->temperature;
return $temp;
}
function fe_get_wp_temp_f() {
$temp = fe_get_wp_temp_api_call(); // SLOW.
return $temp;
}
set_transient(
$transient_key, // Unique key (max length 172).
$value, // Value to cache.
$max_time // Max time in seconds to keep.
);
get_transient( $transient_key );
// Returns the cached value or false.
function fe_get_wp_temp_f() {
$temp = fe_get_wp_temp_api_call(); // SLOW.
return $temp;
}
function fe_get_wp_temp_f() {
$temp = fe_get_wp_temp_api_call(); // SLOW.
set_transient('fe_wp_temp', $temp, 1800 );
return $temp;
}
function fe_get_wp_temp_f() {
$temp = get_transient( 'fe_wp_temp' );
$temp = fe_get_wp_temp_api_call(); // SLOW.
set_transient('fe_wp_temp', $temp, 1800 );
return $temp;
}
function fe_get_wp_temp_f() {
$temp = get_transient( 'fe_wp_temp' );
if ( false !== $temp ) { return $temp; }
$temp = fe_get_wp_temp_api_call(); // SLOW.
set_transient('fe_wp_temp', $temp, 1800 );
return $temp;
}
set_transient(
$transient_key, // Unique key (max length 172).
$value, // Value to cache.
$max_time // Max time in seconds to keep.
);
get_transient( $transient_key );
// Returns the cached value or false.
Getting a transient is approximately 1,000 times faster than a HTTP API Call.
Stores two values
Number of seconds since midnight January 1, 1970 UTC
e.g. 1570312800
_transient_{transient_key}
_transient_timeout_{transient_key}
_transient_fe_wp_temp
_transient_timeout_fe_wp_temp
_transient_fe_wp_temp | 59 |
---|---|
_transient_timeout_fe_wp_temp | 1570308600 |
Expired transients are deleted by get_transient()
Abandoned transients are never deleted.
on Plugin Deactivation
When I Can't Recreate the Data
$max_time = 1800;
$max_time = 30 * MINUTE_IN_SECONDS;
$max_time = 1 * DAY_IN_SECONDS;