vendredi 9 octobre 2015

Laravel 5.1 Middleware caching doesn't catch Route-Model bindings

I've got a middleware setup that's caching the HTML output of each public Controller request, in each of my controllers' __construct method.

public function __construct() {
    $this->middleware('auth', ['except' => ['index', 'show']]);
    $this->middleware('cache.get', ['only' => 'show']);
    $this->middleware('cache.put', ['only' => 'show']);
}

The caching is working great, as expected, except for one thing: I've got Route-Model bindings setup in RouteServiceProvider.php for easy accessiblity of models in their respective controllers, like

public function boot(Router $router)
{
    parent::boot($router);

    $router->bind('posts', function($id) {
       return \App\Article::findBySlugOrIdOrFail($id);
    });

    $router->bind('tags', function($name) {
        return \App\Tag::where('name', $name)->firstOrFail();
    });

    $router->bind('artists', function($slug) {
        return \App\Artist::findBySlugOrIdOrFail($slug);
    });

Basically what's happening is even when pages are cached, I'm still getting a single query for each route where it's looking up that slug (SluggableInterface) or id. Wondering if there's a way to do this where the query doesn't occur when a route is cached? Or is that just not possible?

Thanks!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire