Title: Caching Code over here!
Last modified: August 30, 2016

---

# Caching Code over here!

 *  [scottdurban](https://wordpress.org/support/users/scottdurban/)
 * (@scottdurban)
 * [11 years ago](https://wordpress.org/support/topic/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 with
 *     ```
       function 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!
 * [https://wordpress.org/plugins/ai-twitter-feeds/](https://wordpress.org/plugins/ai-twitter-feeds/)

The topic ‘Caching Code over here!’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/ai-twitter-feeds_bde0ed.svg)
 * [AI Twitter Feeds (Twitter widget & shortcode)](https://wordpress.org/plugins/ai-twitter-feeds/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ai-twitter-feeds/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ai-twitter-feeds/)
 * [Active Topics](https://wordpress.org/support/plugin/ai-twitter-feeds/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ai-twitter-feeds/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ai-twitter-feeds/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [scottdurban](https://wordpress.org/support/users/scottdurban/)
 * Last activity: [11 years ago](https://wordpress.org/support/topic/caching-code-over-here/)
 * Status: not resolved