Skip to content

Commit

Permalink
fixes bug with global fed caps cache
Browse files Browse the repository at this point in the history
  • Loading branch information
kmarshgov committed Jan 31, 2025
1 parent 5286bae commit 96aaa90
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Modules/Ministry/App/Http/Controllers/FedCapController.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ public function setDefault(Request $request)
$fedCap = FedCap::where('guid', $request->input('fed_cap_guid'))->first();

Cache::forget('global_fed_caps_' . Auth::id());

// Sometimes Auth::id() is null and we need to enforce attaching the id to the cache
if(!is_null(Auth::id())){
\Log::info('updating global fed caps for: ' . Auth::id());
// \Log::info('updating global fed caps for: ' . Auth::id());
Cache::remember('global_fed_caps_' . Auth::id(), now()->addHours(10), function () use ($fedCap) {
$fedCaps = FedCap::select('id', 'guid', 'start_date', 'end_date', 'status')
->without(['caps'])
Expand Down
3 changes: 3 additions & 0 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ public function login(Request $request)
*/
public function logout(Request $request)
{
if(Auth::check()){
Cache::forget('global_fed_caps_' . Auth::id());
}
Auth::logout();
$request->session()->invalidate();
$request->session()->regenerateToken();
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Middleware/HandleInertiaRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ public function share(Request $request): array
if (Auth::check()) {
$user = User::find(Auth::id());

// Sometimes Auth::id() is null and we need to enforce attaching the id to the cache
if(!is_null(Auth::id())){
\Log::info('Updating Global Fed Caps for: ' . Auth::id());
// \Log::info('Updating Global Fed Caps for: ' . Auth::id());

$globalFedCaps = Cache::remember('global_fed_caps_' . Auth::id(), now()->addHours(10), function () {
$fedCaps = FedCap::select('id', 'guid', 'start_date', 'end_date', 'status')
Expand Down

0 comments on commit 96aaa90

Please sign in to comment.