dongshi3605 2014-01-28 16:24
浏览 23
已采纳

Laravel 4:记住()结果来自:: all()

Is it possible to apply the remember(60) function to something like Service::all()?

This is a data set that will rarely change. I've attempted several variations with no success:

  • Service::all()->remember(60);
  • Service::all()->remember(60)->get();
  • (Service::all())->remember(60);

Of course, I am aware of other caching methods available, but I prefer the cleanliness of this method if available.

  • 写回答

1条回答 默认 最新

  • dongliang1996 2014-01-28 16:33
    关注

    Yes, you should be able to simply swap the two such as

    Change

    Service::get()->remember(60);
    

    to

    Service::remember(60)->get();
    

    An odd quirk I agree, but after I ran into this a few weeks back and realized all I had to do was put remember($time_to_remember) in front of the rest of the query builder it works like a charm.

    For your perusing pleasure: See the Laravel 4 Query Builder Docs Here

    /**
      * Indicate that the query results should be cached.
      *
      * @param  int  $minutes
      * @param  string  $key
      * @return \Illuminate\Database\Query\Builder
      */
    
     public function remember($minutes, $key = null)
     {
         list($this->cacheMinutes, $this->cacheKey) = array($minutes, $key);
         return $this;
     }
    

    L4 Docs - Queries

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 统计大规模图中的完全子图问题
  • ¥15 使用LM2596制作降压电路,一个能运行,一个不能
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 经gamit解算的cors站数据再经globk网平差得到的坐标做形变分析
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式