Skip to content

Commit

Permalink
Added model caching
Browse files Browse the repository at this point in the history
  • Loading branch information
hillelcoren committed Jul 13, 2018
1 parent c1122a5 commit 9ebd9dc
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,6 +2,7 @@
/public/hot
/public/storage
/storage/*.key
/storage/debugbar
/vendor
/.idea
/.vscode
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/FlutterAppController.php
Expand Up @@ -34,7 +34,7 @@ public function __construct(FlutterAppRepository $appRepo)
*/
public function index()
{
$apps = FlutterApp::whereIsVisible(true)->latest()->get();
$apps = cache('flutter-app-list');

return view('flutter_apps.index', compact('apps'));
}
Expand Down
42 changes: 42 additions & 0 deletions app/Observers/FlutterAppObserver.php
@@ -0,0 +1,42 @@
<?php

namespace App\Observers;

use App\Models\FlutterApp;
use Cache;

class FlutterAppObserver
{
/**
* Handle to the flutter app "created" event.
*
* @param \App\FlutterApp $flutterApp
* @return void
*/
public function created(FlutterApp $flutterApp)
{
Cache::forget('flutter-app-list');
}

/**
* Handle the flutter app "updated" event.
*
* @param \App\FlutterApp $flutterApp
* @return void
*/
public function updated(FlutterApp $flutterApp)
{
Cache::forget('flutter-app-list');
}

/**
* Handle the flutter app "deleted" event.
*
* @param \App\FlutterApp $flutterApp
* @return void
*/
public function deleted(FlutterApp $flutterApp)
{
Cache::forget('flutter-app-list');
}
}
26 changes: 17 additions & 9 deletions app/Providers/AppServiceProvider.php
Expand Up @@ -3,24 +3,32 @@
namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use App\Models\FlutterApp;
use App\Observers\FlutterAppObserver;
use Cache;

class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
//
FlutterApp::observe(FlutterAppObserver::class);

Cache::rememberForever('flutter-app-list', function () {
return FlutterApp::whereIsVisible(true)->latest()->get();
});

}

/**
* Register any application services.
*
* @return void
*/
* Register any application services.
*
* @return void
*/
public function register()
{
//
Expand Down
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -13,6 +13,7 @@
"laravelcollective/html": "^5.6.0"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.1",
"filp/whoops": "^2.0",
"fzaninotto/faker": "^1.4",
"mockery/mockery": "^1.0",
Expand Down
131 changes: 130 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9ebd9dc

Please sign in to comment.