From fa4be697741eb706b8eaaf186c37dfa11b1238d0 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Thu, 7 Dec 2017 17:44:05 -0600 Subject: [PATCH] Cache the api calls to vacentral and make the iata field optional --- .gitignore | 1 + .idea/composerJson.xml | 12 ------------ app/Http/Controllers/Api/AirportController.php | 10 +++++++++- config/cache.php | 6 +++++- .../2017_06_11_135707_create_airports_table.php | 2 +- 5 files changed, 16 insertions(+), 15 deletions(-) delete mode 100644 .idea/composerJson.xml diff --git a/.gitignore b/.gitignore index c5363902..7a73e7a7 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,7 @@ Homestead.json tmp/ # intellij files +.idea/composerJson.xml .idea/**/workspace.xml .idea/**/tasks.xml .idea/dictionaries diff --git a/.idea/composerJson.xml b/.idea/composerJson.xml deleted file mode 100644 index a797501e..00000000 --- a/.idea/composerJson.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/app/Http/Controllers/Api/AirportController.php b/app/Http/Controllers/Api/AirportController.php index 228cfdb5..6f4d9245 100644 --- a/app/Http/Controllers/Api/AirportController.php +++ b/app/Http/Controllers/Api/AirportController.php @@ -6,6 +6,7 @@ use App\Repositories\AirportRepository; use App\Http\Controllers\AppBaseController; use App\Http\Resources\Airport as AirportResource; +use Illuminate\Support\Facades\Cache; use VaCentral\Airport as AirportLookup; class AirportController extends AppBaseController @@ -25,7 +26,14 @@ class AirportController extends AppBaseController */ public function lookup($id) { - $airport = AirportLookup::get($id); + $airport = Cache::remember( + config('cache.keys.AIRPORT_VACENTRAL_LOOKUP.key') . $id, + config('cache.keys.RANKS_PILOT_LIST.time'), + function () use ($id) { + return AirportLookup::get($id); + } + ); + return new AirportResource(collect($airport)); } } diff --git a/config/cache.php b/config/cache.php index c2440fda..c3d7acae 100755 --- a/config/cache.php +++ b/config/cache.php @@ -6,9 +6,13 @@ return [ 'prefix' => env('CACHE_PREFIX', ''), 'keys' => [ + 'AIRPORT_VACENTRAL_LOOKUP' => [ + 'key' => 'airports:lookup:', + 'time' => 1800, + ], 'RANKS_PILOT_LIST' => [ 'key' => 'ranks:pilot_list', - 'time' => 1440, + 'time' => 600, ] ], diff --git a/database/migrations/2017_06_11_135707_create_airports_table.php b/database/migrations/2017_06_11_135707_create_airports_table.php index 19ac565a..b602b81f 100644 --- a/database/migrations/2017_06_11_135707_create_airports_table.php +++ b/database/migrations/2017_06_11_135707_create_airports_table.php @@ -16,7 +16,7 @@ class CreateAirportsTable extends Migration Schema::create('airports', function (Blueprint $table) { // $table->bigIncrements('id'); $table->string('id', 5)->primary(); - $table->string('iata', 5); + $table->string('iata', 5)->nullable(); $table->string('icao', 5); $table->string('name', 100); $table->string('location', 100)->nullable();