AD:
		
		
	
	Google AnalytcsのAPIを使用してページ表示ランキングを作っていたのですが、GAのAPIはアクセスに制限があるのとリスポンスが遅かったので結果をキャッシュに入れておきました。
いろいろなキャッシュに入れる方法がありますが、先日set_transient()ものを知ったので、さっそく使ってみました。
こんな感じで使用しております。
86400で1日間の有効期限を与えております。
| 
					 1 2 3 4 5 6  | 
						// get_transientですでにキャッシュが作られているか確認 if ( false === ( $result = get_transient( 'special_query_results' ) ) ) {   // ない場合はしかたないので、APIを走らせる 86400は1日   $result = $this->_ga_request_report_data($filters, $max_results);   set_transient( 'special_query_results', $result, 86400 ); }  | 
					
		AD:
			
			
		
		
	
No Comments, Comment or Ping
Reply to “WordPressでset_transient & get_transientを使ってキャッシュを利用する”
Warning: Undefined variable $user_ID in /home/sazaeau/mizoshiri.com/public_html/blog.mizoshiri.com/wp-content/themes/grid_focus_public_mizo/comments.php on line 66
You must be logged in to post a comment.