3
我在查詢緩存時遇到問題。每次我打我的API時,我都會從數據庫中獲得新的結果,而不是我要去的緩存結果。奇怪的是,如果我查看文件緩存,我可以看到緩存結果,它們正是我期望的內容,但是當我調用API時,我會得到新的結果。以下是相關文件的一些片段。我在哪裏錯了?Laravel 4查詢緩存
存儲功能我的API調用:
public function topMonth()
{
$top = $this->repository->month()->top()->joinUser()->remember(30)->get(['things.id', 'things.votes', 'things.title', 'things.description', 'things.tags', 'things.created_at', 'users.id as user_id','users.username','users.picture as user_picture'])->toArray();
return $top;
}
型號
class Thing extends Eloquent
{
public function scopeTop($query)
{
return $query->orderBy('things.votes', 'desc');
}
public function scopeYear($query)
{
return $query->whereRaw("things.created_at > STR_TO_DATE('" . Carbon::now()->subYear() . "', '%Y-%m-%d %H:%i:%s')");
}
public function scopeMonth($query)
{
return $query->whereRaw("things.created_at > STR_TO_DATE('" . Carbon::now()->subMonth() . "', '%Y-%m-%d %H:%i:%s')");
}
public function scopeWeek($query)
{
return $query->whereRaw("things.created_at > STR_TO_DATE('" . Carbon::now()->subWeek() . "', '%Y-%m-%d %H:%i:%s')");
}
public function scopeDay($query)
{
return $query->whereRaw("things.created_at > STR_TO_DATE('" . Carbon::now()->subDay() . "', '%Y-%m-%d %H:%i:%s')");
}
public function scopeJoinUser($query)
{
return $query->join('users', function($join)
{
$join->on('users.id', '=', 'things.created_by');
});
}
}
謝謝你不只是給出答案,而是解釋爲什麼它是如何。你是一個紳士和學者! –