Remove static cache from our_address in favour of Cache::class keyed off setup:system_id

This commit is contained in:
Deon George 2024-04-26 17:27:00 +10:00
parent 9abfd88e3d
commit 92f964f572
2 changed files with 12 additions and 8 deletions

View File

@ -2,6 +2,7 @@
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;
use App\Models\{Address,Domain,Setup}; use App\Models\{Address,Domain,Setup};
@ -92,16 +93,15 @@ if (! function_exists('hexstr')) {
*/ */
function our_address(Domain|Address $o=NULL): Collection|Address|NULL function our_address(Domain|Address $o=NULL): Collection|Address|NULL
{ {
static $so = NULL; $so = Cache::remember('so',5,function() {
static $our = NULL; return Setup::findOrFail(config('app.id'));
});
if (! $so) $our = Cache::remember(sprintf('%d-akas',$so->system_id),60,function() use ($so) {
$so = Setup::findOrFail(config('app.id'));
if (! $our) {
$so->load(['system.akas.zone.domain']); $so->load(['system.akas.zone.domain']);
$our = $so->system->akas;
} return $so->system->akas;
});
// If we dont have any addresses // If we dont have any addresses
if ($our->count() === 0) if ($our->count() === 0)

View File

@ -4,6 +4,7 @@ namespace Tests\Feature;
use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Collection;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Cache;
use Tests\TestCase; use Tests\TestCase;
use App\Models\{Address,Domain,Setup,System}; use App\Models\{Address,Domain,Setup,System};
@ -268,10 +269,12 @@ class RoutingTest extends TestCase
public function test_complex_rc_nc_hc_us() public function test_complex_rc_nc_hc_us()
{ {
Cache::forget('so');
$setup = Setup::findOrFail(config('app.id')); $setup = Setup::findOrFail(config('app.id'));
$ao = Address::findFTN('100:10/0.0@a'); $ao = Address::findFTN('100:10/0.0@a');
$setup->system_id = $ao->system_id; $setup->system_id = $ao->system_id;
$setup->save(); $setup->save();
$this->assertEquals('100:10/0.0@a',our_address($ao)?->ftn);
$this->session_rc(); $this->session_rc();
//$this->session_nc(); //$this->session_nc();
@ -303,6 +306,7 @@ class RoutingTest extends TestCase
$ao = Address::findFTN('100:10/22.0@a'); $ao = Address::findFTN('100:10/22.0@a');
$this->assertEquals('100:10/20.0@a',$ao->parent()->ftn); $this->assertEquals('100:10/20.0@a',$ao->parent()->ftn);
Cache::forget('so');
} }
// A points parent is the node, if we have traffic for a point and we have session details for the node // A points parent is the node, if we have traffic for a point and we have session details for the node