user1419810
user1419810

Reputation: 846

Wordpress Json API Cache

I am using Wordpress as a feed for an iPhone app by using the json api plugin to feed the data from site to application. It is however quite slow so I'm trying to find a way to cache the request. I haven't found a solution that actually works/explains how to do this well, can anyone provide any guidance oh how/wether this can be done?

Many thanks

Upvotes: 4

Views: 3480

Answers (1)

Dipesh KC
Dipesh KC

Reputation: 3297

I suggest using wordpress transient API. eg.

 $transient_name = 'some_api_req_param1';
 $transient_value = get_transient($transient_name); 
 if( false !== $transient_value){
  echo $transient_value;
 }else{
  //$result = ...
  //fetch your data here
  //in the end save the data in the transient
  $expiration_time = 60*60*24*7;//in second 
  set_transient($transient_name,$result,$expiration_time);
}

Upvotes: 6

Related Questions