Caching Code over here!
-
Hi guys, I was having a problem with caching, apparently it is included, however I added a more manual option for those who’d like to adapt the plugin.
First create cache/json.txt in your plugin directory.
Go to line 218 in ai-twitter-feeds.php and replace the get_connect function withfunction get_connect($ai_consumerkey_gt, $ai_consumersecret_gt, $ai_accesstoken_gt, $ai_accesstokensecret_gt,$ai_twitteruser_gt,$ai_notweets_gt){ $filename = plugin_dir_path( __FILE__ ) . 'cache/json.txt'; if (time()-filemtime($filename) > 1 * 3600) { $ai_connection = getConnectionWithAccessToken($ai_consumerkey_gt, $ai_consumersecret_gt, $ai_accesstoken_gt, $ai_accesstokensecret_gt); $ai_tweets_all = $ai_connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$ai_twitteruser_gt."&count=".$ai_notweets_gt); $result = $ai_tweets_all; //Write to file $myfile = fopen($filename, "w") or die("Unable to open file!"); $result = serialize($result); fwrite($myfile, $result); fclose($myfile); } else { // file younger than 1 hour $file = $filename; $result = file_get_contents($file); $result = unserialize($result); $ai_tweets_all = $result; } return $ai_tweets_all; }
Hope this helps someone!
- The topic ‘Caching Code over here!’ is closed to new replies.