【问题标题】:Wordpress Json API CacheWordpress Json API 缓存
【发布时间】:2012-08-18 04:17:55
【问题描述】:

我正在使用 Wordpress 作为 iPhone 应用程序的提要,通过使用 json api 插件将数据从站点提供到应用程序。然而它很慢,所以我试图找到一种方法来缓存请求。我还没有找到真正有效/解释如何做好这件事的解决方案,任何人都可以提供任何指导哦,如何/是否可以做到这一点?

非常感谢

【问题讨论】:

  • 你找到解决办法了吗?您是否尝试过从后端做一些事情,例如使用缓存插件来缓存至少每次重复的数据库查询?我正在使用 JSON 来获取我想要的数据,而且还不错。从 EC2 服务器上的帖子中抓取所有内容至少需要 1 秒

标签: json wordpress api caching


【解决方案1】:

我建议使用wordpress transient API。 例如。

 $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);
}

【讨论】:

    猜你喜欢
    • 2015-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-01
    • 1970-01-01
    • 2017-06-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多