From ef47a50cf2c409d7413acfb40a27bf955f6d52e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nil=20Portugu=C3=A9s=20Calder=C3=B3?= Date: Tue, 5 Jan 2016 01:38:37 +0100 Subject: [PATCH] Caching --- .../Laravel5/JsonApi/Providers/Laravel51Provider.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/NilPortugues/Laravel5/JsonApi/Providers/Laravel51Provider.php b/src/NilPortugues/Laravel5/JsonApi/Providers/Laravel51Provider.php index c4cbc0f..97dfbe1 100644 --- a/src/NilPortugues/Laravel5/JsonApi/Providers/Laravel51Provider.php +++ b/src/NilPortugues/Laravel5/JsonApi/Providers/Laravel51Provider.php @@ -10,6 +10,7 @@ namespace NilPortugues\Laravel5\JsonApi\Providers; +use Illuminate\Support\Facades\Cache; use NilPortugues\Api\JsonApi\JsonApiTransformer; use NilPortugues\Api\Mapping\Mapping; use NilPortugues\Laravel5\JsonApi\JsonApiSerializer; @@ -24,14 +25,11 @@ class Laravel51Provider public function provider() { return function ($app) { - $mapping = $app['config']->get('jsonapi'); - $transformer = new JsonApiTransformer($this->parseRoutes(new Mapper($mapping))); + $parsedRoutes = Cache::rememberForever('jsonapi.mapping', function () use ($app) { + return $this->parseRoutes(new Mapper($app['config']->get('jsonapi'))); + }); - $cacheableConfig = function () use ($transformer) { - return new JsonApiSerializer($transformer); - }; - - return $cacheableConfig(); + return new JsonApiSerializer(new JsonApiTransformer($parsedRoutes)); }; }