Search code examples
wordpressapicachingamazon-advertising-api

Caching Amazon api data once a day


I created a plugin to get some info from Amazon though Amazon product advertising API.

My function returns an array of info that I would like to cache once a day based on the keywordk used in the itemsearch (I use a shortcode in the content to input keyword for the API call)

Is there any simple solution to make it happen?

Thanks


Solution

  • I solved the issue through the Wordpress Transient API (http://codex.wordpress.org/Transients_API) in the following way:

    if ( false === ( $product_info = get_transient( $kw ) ) ) {
    // It wasn't there, so regenerate the data and save the transient
    $product_info = my_function_to_getinfo( $kw );      
    set_transient( $kw, $product_info, 24 * HOUR_IN_SECONDS );
    }