Skip to content

Commit

Permalink
Cache the api calls to vacentral and make the iata field optional
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeelio committed Dec 7, 2017
1 parent ddb8a6f commit fa4be69
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -27,6 +27,7 @@ Homestead.json
tmp/

# intellij files
.idea/composerJson.xml
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries
Expand Down
12 changes: 0 additions & 12 deletions .idea/composerJson.xml

This file was deleted.

10 changes: 9 additions & 1 deletion app/Http/Controllers/Api/AirportController.php
Expand Up @@ -6,6 +6,7 @@
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
Expand All @@ -25,7 +26,14 @@ public function __construct(
*/
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));
}
}
6 changes: 5 additions & 1 deletion config/cache.php
Expand Up @@ -6,9 +6,13 @@
'prefix' => env('CACHE_PREFIX', ''),

'keys' => [
'AIRPORT_VACENTRAL_LOOKUP' => [
'key' => 'airports:lookup:',
'time' => 1800,
],
'RANKS_PILOT_LIST' => [
'key' => 'ranks:pilot_list',
'time' => 1440,
'time' => 600,
]
],

Expand Down
Expand Up @@ -16,7 +16,7 @@ public function up()
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();
Expand Down

0 comments on commit fa4be69

Please sign in to comment.