Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caching paginated results #7

Open
mgarciadelojo opened this issue Mar 3, 2016 · 3 comments
Open

Caching paginated results #7

mgarciadelojo opened this issue Mar 3, 2016 · 3 comments

Comments

@mgarciadelojo
Copy link

Hi Jeffrey,

First of all, thank you very much for this package. I am a big fan of laracasts :)

I was trying to use the russian doll caching in a view with pagination, so to make it work I have to have this in my controller...

$collection = Collection::make($results->items);

... and then pass it to the view. This way I can cache the results, but I am speding twice the memory. By the way, to allow @cache directive to cache collections I needed to run:

composer require laracasts/matryoshka:dev-master

Do you come up any idea how can I solve this?

Thanks in advance,

@ctf0
Copy link

ctf0 commented Jun 22, 2016

am in the same boat so i came up with a little somthing

@inject('Model','App\Post')

@foreach ($posts as $post)
    @cache("Posts/$post->id-".$Model->cacheDate($post->updated_at))
        ...
    @endcache
@endforeach

cacheDate is basically turning the value into timestamp, and we had to inject the model as the pagination returns an array so calling the method directly on $post wont work.

public function cacheDate($value) {
     return Carbon::parse($value)->timestamp;
}

and now everything works as usual without changing anything in the original code 😉

@mgarciadelojo
Copy link
Author

Hi @ctf0,

Thank you for your reply. This solution may work, but, instead of caching all the page (as I wanted), you are caching those items one by one.

I finally ended up using redis to cache the collection and passing it to the view. It was a lot faster than using this package.

Cheers,

@ctf0
Copy link

ctf0 commented Jun 23, 2016

the problem with caching the whole page is when a fragment of that page is updated, u will have to regenerate the whole thing which is the exact opposite of what this package for.

EDIT:
just a headsup, this type of caching is a nightmare for multilang, u r better off without it.

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

No branches or pull requests

2 participants