File tree Expand file tree Collapse file tree
Modules/CIPPCore/Public/TenantGroups Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ if (-not $script:TenantGroupsResultCache) {
1212 $script :TenantGroupsResultCache = @ {}
1313}
1414
15+ $script :TenantGroupsCacheTTL = (New-TimeSpan - Minutes 5 )
16+
1517function 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 = @ {}
You can’t perform that action at this time.
0 commit comments