mercredi 22 avril 2015

How to cache third party API access in SQL database for a WordPress plugin

Is there any way to cache data for a WordPress plugin ? I have a ready one that uses third party API access to YouTube API V3 and I need to apply cache for both optimization and keeping the hits under the quota.

Supposing I have this function:

function popular_uploads() {
        $url = ''. channel_id(). '&maxResults=5&key={key}&type=video';
        $json = file_get_contents($url);
        $json_data = json_decode($json, false);
        foreach ( $json_data->items as $item ) {
            $id = $item->id->videoId;
            echo '<iframe id="ytplayer" type="text/html" width="auto" height="auto" 
                src="//' . $id . '?rel=0&showinfo=1"
                frameborder="0" allowfullscreen></iframe>';

How am I going to cache the data for sometime in a database ? I am really new to this process and I have looked it up and couldn't find a fix.

Thank you so much for assisting a beginner!


Aucun commentaire:

Enregistrer un commentaire