DeveloperBreeze

Application Configurations. Development Tutorials, Guides & Insights

Unlock 1+ expert-curated application configurations. tutorials, real-world code snippets, and modern dev strategies. From fundamentals to advanced topics, boost your application configurations. skills on DeveloperBreeze.

Optimizing Performance in Laravel by Centralizing Data Loading

Tutorial November 16, 2024
php

   namespace App\Providers;

   use Illuminate\Support\ServiceProvider;
   use Illuminate\Support\Facades\Cache;

   class PerformanceServiceProvider extends ServiceProvider
   {
       public function register()
       {
           // Register a singleton for shared data
           $this->app->singleton('sharedData', function () {
               return Cache::rememberForever('shared_data', function () {
                   return [
                       'max_uploads' => 10, // Example limit
                       'api_rate_limit' => 100, // API requests per minute
                       'features' => [
                           'uploads_enabled' => true,
                           'comments_enabled' => false,
                       ],
                   ];
               });
           });
       }
   }

Add the provider to the providers array in config/app.php: