-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from maester365/merill-patch-1
Added Invoke-MtGraphRequest
- Loading branch information
Showing
14 changed files
with
194 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<# | ||
.SYNOPSIS | ||
Enhanced version of Invoke-MgGraphRequest that supports caching. | ||
#> | ||
Function Invoke-MtGraphRequestCache { | ||
[CmdletBinding()] | ||
param( | ||
[Parameter(Mandatory = $true)] | ||
[Uri] $Uri, | ||
[Parameter(Mandatory = $false)] | ||
[string] $Method = 'GET', | ||
[Parameter(Mandatory = $false)] | ||
[string] $OutputType, | ||
[Parameter(Mandatory = $false)] | ||
[System.Collections.IDictionary] $Headers, | ||
# Specify if this request should skip cache and go directly to Graph. | ||
[Parameter(Mandatory = $false)] | ||
[switch] $DisableCache | ||
) | ||
|
||
$results = $null | ||
$isBatch = $uri.AbsoluteUri.EndsWith('$batch') | ||
$isInCache = $MtGraphCache.ContainsKey($Uri.AbsoluteUri) | ||
$cacheKey = $Uri.AbsoluteUri | ||
$isMethodGet = $Method -eq 'GET' | ||
|
||
if (!$DisableCache -and !$isBatch -and $isInCache -and $isMethodGet) { | ||
# Don't read from cache for batch requests. | ||
Write-Verbose ("Checking cache: $($cacheKey)") | ||
$results = $MtGraphCache[$cacheKey] | ||
} | ||
|
||
if (!$results) { | ||
$results = Invoke-MgGraphRequest -Method $Method -Uri $Uri -Headers $Headers -OutputType $OutputType | ||
if (!$isBatch -and $isMethodGet) { | ||
# Update cache | ||
if ($isInCache) { | ||
$MtGraphCache[$cacheKey] = $results | ||
} else { | ||
$MtGraphCache.Add($cacheKey, $results) | ||
} | ||
} | ||
} | ||
return $results | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
<# | ||
.SYNOPSIS | ||
Resets the local cache of Graph API calls. Use this if you need to force a refresh of the cache in the current session. | ||
#> | ||
function Clear-MtGraphCache { | ||
$MtGraphCache.Clear() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.