No quite: Get the transient’s content first, then do the expensive work to fetch the external resource.
function google_transient() {
$transient_name="google";
$content = get_transient( $transient_name );
// done
if ( $content )
return $content;
$url="http://www.google.com";
$content = wp_remote_retrieve_body( wp_remote_get($url) );
set_transient( $transient_name, $content, DAY_IN_SECONDS ); // 24 hour cache
return $content;
}
Related Posts:
- When should I be using the Transients API?
- Cache remote (HTTP) request with Transients API
- Is there any danger in deleting all transients?
- Why are transients cleared prematurely?
- Get a list of existing transients
- Storing posts social counters by using transient api
- How to save new transients if query changes?
- Integrating WP-TLC-Transients with WordPress – Where to Begin?
- Is priming a Transient Cache possible?
- What causes a transient to changes status to “Does Not Expire”?
- Reset Transient on New Day
- How to use transients and variables
- Transient storage location? database/xcache/w3Total Cache?
- How to delete transients written by fetch_feed()?
- Set Transient expiration
- WordPress transient doesn’t use the transient
- How do I reset a transient when updating a widget’s value?
- How to clear Transients on all sites in Multi Sites environment
- Should I use the Transients API to temporarily hold edited attachements?
- transient or not transient
- Can Transients be used to store sensitive data?
- wp_options flooded with transient API entires
- Why Transients may not work correctly?
- How many transients is too many transients
- Synchronize Data every minute with set_transient
- Difference between get_site_transient() and get_transient()
- delete_transient on click inside a widget form
- Set_Transient to end at midnight
- Whats wrong with this transient? Not caching as expected
- Set transient with get posts error
- Clear Transients
- Unique Transients user id for Non-Logged In users
- Transient is never set. Why?
- Button to clear transients
- Set transient name
- Hacked site using transient API?
- Ajax call to transients
- Why can’t I save encrypted data in a transient?
- Doesn’t set_transient() add multiple rows with the same key?
- Are transients garbage collected?
- Is get_option() faster than accessing get_transient()?
- wp-cron.php – How are WP’s Cron transients removed?
- Do WordPress’ cron’s clean up expired transients?
- What’s the case against transient-ing almost everything that’s mostly static?
- Fragment caching increasing database queries
- Should I store external API data in my WP database or keep it as a transient?
- WordPress transients for a shortcode
- How to delete a transient on post/page publish?
- How to make sure that only one wp_cron() runs at a time?
- Transients vs CRON +Custom Fields: Caching Data Per Post
- WP_Cron doesn’t do the job: Multisite stats
- Storing an XML Response (Transient)?
- Transients API and multisite
- What to use , set_transient, set_option or file system? [closed]
- Transient caching for wp query
- how to get the value of time left for a transient
- How does WordPress handle sessions?
- WordPress Caching – Transients API or “update_user_meta ” Cronjob?
- Can set_transient() be used in multi-site?
- Minimize database queries to user tables?
- Transient unique names
- How to use transient in this code for related post?
- Store sticky post’s ids in a transient
- Delete a WordPress transient from a shortcode on Page/Post update
- Transients are not expiring as expected in simple custom plugin
- Store a default value for a transient on plugin activation
- Is using custom table to suit business needs instead of transients a big hit to page load speed?
- Transient not behaving as expected
- How to decode wordpress transient cache stored in database?
- How to make use of Transient API as cookie
- Transients API conditional
- After having installed APC Object Cache Backend transients stopped working
- Transients with dynamic WP_Query
- How to cache wp_query with pagination using transients?
- Compare custom taxonomies of updated post (or new post) [Updated with progress]
- passing markup thought a shortcode attribute
- Compare transient data with a meta box value
- WordPress transient not working with WP Engine
- Using Transients
- How to write update query in WordPress to expire transients
- Workflow for new importer plugin – your advices?
- Storing temporary data for a custom post type
- I am officially missing something about transient posts
- Managing and deleting transients with dynamically generated transient names
- Using `set_transient()` when saving a custom post type
- Change WooCommerce product and variation prices programatically without affecting performance
- set_transient fails if the value has more than 60.000 characters
- Set user status to absent on WordPress
- Is it possible to restore an expired transient?
- Transient not working for external data
- Hi , i am trying to set the post for 24 hours and with it will be changed
- How to use a transient inside WP_User_Query
- Add Hook for clearing transient when post is added
- Delete Transient when clicking ‘Save Changes’ on options page
- Set Transient on CPT
- How to optimize performance without transient?
- how to use transient method?
- How to create a transient that persists the data for the whole duration of the expiration, even when object cache is enabled?
- How can i store cache of wordpress a database request without plugins?
- How to cache wordpress get_posts query using transients?