0

I am trying to cache database query as given below (Laravel 5.7):

Cache::remember('footer_pages', 180, function () {
    DB::table('pages')->select('id', 'title')->where(array('status' => 'Published', 'menu_position' => 'Footer'))->orderBy('sort', 'ASC')->get();
});

But Cache is empty. Please help me find what mistake I did.

2
  • do return DB::table.... The function remember will cache the result of the callback Commented Dec 6, 2018 at 18:09
  • thanks a lot. plz post is as answrr Commented Dec 6, 2018 at 18:10

1 Answer 1

2

The remember function will store the result of the callback in the cache if a callback is provided.

That means you need to make your callback return the result you want stored:

Cache::remember('footer_pages', 180, function () {
    return DB::table('pages')->select('id', 'title')->where(array('status' => 'Published', 'menu_position' => 'Footer'))->orderBy('sort', 'ASC')->get();
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.