Support the ongoing development of Laravel.io →
Cache Architecture
Last updated 2 years ago.
0

The below code is a little shorter but does the same thing

10 min cache

$users = Cache::remember('users', 10, function() {
    return User::get();
});

cache forever but attach a tag so you can flush it

$users = Cache::tags('user')->rememberForever('users', function() {
    return User::get();
});


Cache::tags('user')->flush();

source: http://laravel.com/docs/cache

Last updated 2 years ago.
0

I don't thing stuff like caching should be in a presenter, a presenter to me is a class that formats 1.66666 into € 1.67

My repositories handle the cache. I usually cache every thing with rememberForever() and flush the cache based on tags when CRUD the same type of object

Last updated 2 years ago.
0

zenry said:

I don't thing stuff like caching should be in a presenter, a presenter to me is a class that formats 1.66666 into € 1.67

My repositories handle the cache. I usually cache every thing with rememberForever() and flush the cache based on tags when CRUD the same type of object

The design pattern we're thinking of is a Decorator (http://en.wikipedia.org/wiki/Decorator_design_pattern), of which a Presenter is a subset.

Last updated 2 years ago.
0

zenry said:

I don't thing stuff like caching should be in a presenter, a presenter to me is a class that formats 1.66666 into € 1.67

My repositories handle the cache. I usually cache every thing with rememberForever() and flush the cache based on tags when CRUD the same type of object

I would be interested in seeing some code examples in the context of the actual files you use them in.

Last updated 2 years ago.
0

I don't like the idea of mixing both cache and data persistence/fetching. I haven't done much yet in regards of caching but I've thought about creating a Cached[Resource]Repository which decorates a concrete implementation of a repository contract.

I've wrote a quick snippet to show you what I think I'll be doing (or along the lines of), for my project, you can see that here

This is a much more ideal solution than putting the caching AND fetching in one place, I create a new implementation of ProductRepositry I don't want to rewrite the caching layer.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

pyrello pyrello Joined 21 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.