Skip to content
This repository has been archived by the owner on Feb 10, 2019. It is now read-only.

How to cache query result together with relations #383

Open
drmax24 opened this issue Sep 13, 2018 · 1 comment
Open

How to cache query result together with relations #383

drmax24 opened this issue Sep 13, 2018 · 1 comment

Comments

@drmax24
Copy link

drmax24 commented Sep 13, 2018

It is not clear for me how can I cache output result of a complex query.
Let's say I query car accessories together with related cars and other related stuff:

    public function resolve($root, $args, $context, $info)
    {
...
 $result = Accessories
                ::where($where)
                ->get();

        if (Cache::store('redis')->has('all_accessories')) {
            $result = Cache::store('redis')->get('all_accessories');
        } else {
            Cache::store('redis')->put('all_accessories', $result, 10080);
        }

return $result;
    }

If I cache it like this then all relations won't be cached. Because the result does not contain any of them
at the moment of caching. How should i cache it?

@ikudosi
Copy link

ikudosi commented Sep 13, 2018

In my application I am utilizing https://github.com/GeneaLabs/laravel-model-caching/. It covers majority of my caching needs. So far the only downside (and it's been noted) is that it currently does not support belongsToMany caching when being lazy-loaded.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants