Skip to content

Commit

Permalink
Wrapping updateOrCreate in try/catch
Browse files Browse the repository at this point in the history
See this issue: laravel/framework#19372
  • Loading branch information
timcortesi committed Aug 19, 2018
1 parent 6d8dc4b commit 46852e1
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions app/Http/Controllers/AppInstanceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,22 @@ private function http_endpoint(Endpoint $endpoint, $resource_info, $verb, $all_d
abort(505,'Authentication Type Not Supported');
}
if ($resource_info->cache === true || $resource_info->cache === 'true') {
$cache = ResourceCache::updateOrCreate([
'app_instance_id' => $app_instance_id,
'url' => $url,
],[
'content' => serialize($response),
'created_at' => Carbon::now(),
]);
// TJC -- Laravel has a "non-bug" which prevents updateOrCreate from working
// correctly in the event of a race condition. See details:
// https://github.com/laravel/framework/issues/19372
// Wrapping this in try/catch, as I don't really care if the insert
// fails.
try {
$cache = ResourceCache::updateOrCreate([
'app_instance_id' => $app_instance_id,
'url' => $url,
],[
'content' => serialize($response),
'created_at' => Carbon::now(),
]);
} catch (\Exception $e) {
// Move along
}
// Delete Other Stale Cache
ResourceCache::where('created_at','<',Carbon::now()->subMinutes(10)->toDateTimeString())->delete();
}
Expand Down

0 comments on commit 46852e1

Please sign in to comment.