Skip to content

Commit c2a8557

Browse files
committed
fix: expire group cache after 5 minutes
1 parent fa91ec5 commit c2a8557

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

Modules/CIPPCore/Public/TenantGroups/Get-TenantGroups.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ if (-not $script:TenantGroupsResultCache) {
1212
$script:TenantGroupsResultCache = @{}
1313
}
1414

15+
$script:TenantGroupsCacheTTL = (New-TimeSpan -Minutes 5)
16+
1517
function Get-TenantGroups {
1618
<#
1719
.SYNOPSIS
@@ -49,8 +51,9 @@ function Get-TenantGroups {
4951
}
5052
}
5153

52-
# Load table data into cache if not already loaded
53-
if (-not $script:TenantGroupsCache.Groups -or -not $script:TenantGroupsCache.Members -or $SkipCache) {
54+
# Load table data into cache if not already loaded or expired
55+
$CacheExpired = $script:TenantGroupsCache.LastRefresh -and ((Get-Date) - $script:TenantGroupsCache.LastRefresh) -gt $script:TenantGroupsCacheTTL
56+
if (-not $script:TenantGroupsCache.Groups -or -not $script:TenantGroupsCache.Members -or $SkipCache -or $CacheExpired) {
5457
Write-Verbose 'Loading TenantGroups and TenantGroupMembers tables into cache'
5558

5659
$GroupTable = Get-CippTable -tablename 'TenantGroups'
@@ -62,6 +65,7 @@ function Get-TenantGroups {
6265
$script:TenantGroupsCache.Groups = @(Get-CIPPAzDataTableEntity @GroupTable)
6366
$script:TenantGroupsCache.Members = @(Get-CIPPAzDataTableEntity @MembersTable)
6467
$script:TenantGroupsCache.LastRefresh = Get-Date
68+
$script:TenantGroupsResultCache = @{}
6569

6670
# Build MembersByGroup index: GroupId -> array of member objects
6771
$script:TenantGroupsCache.MembersByGroup = @{}

0 commit comments

Comments
 (0)