mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-21 07:10:15 -05:00
33 lines
1,021 B
PowerShell
33 lines
1,021 B
PowerShell
|
|
function Set-IcingaCacheData()
|
||
|
|
{
|
||
|
|
param(
|
||
|
|
[string]$Space,
|
||
|
|
[string]$CacheStore,
|
||
|
|
[string]$KeyName,
|
||
|
|
$Value
|
||
|
|
);
|
||
|
|
|
||
|
|
$CacheFile = Join-Path -Path (Join-Path -Path (Join-Path -Path (Get-IcingaCacheDir) -ChildPath $Space) -ChildPath $CacheStore) -ChildPath ([string]::Format('{0}.json', $KeyName));
|
||
|
|
$cacheData = @{};
|
||
|
|
|
||
|
|
if ((Test-Path $CacheFile)) {
|
||
|
|
$cacheData = Get-IcingaCacheData -Space $Space -CacheStore $CacheStore;
|
||
|
|
} else {
|
||
|
|
New-Item -Path $CacheFile -Force | Out-Null;
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($null -eq $cacheData -or $cacheData.Count -eq 0) {
|
||
|
|
$cacheData = @{
|
||
|
|
$KeyName = $Value
|
||
|
|
};
|
||
|
|
} else {
|
||
|
|
if ($cacheData.PSobject.Properties.Name -ne $KeyName) {
|
||
|
|
$cacheData | Add-Member -MemberType NoteProperty -Name $KeyName -Value $Value -Force;
|
||
|
|
} else {
|
||
|
|
$cacheData.$KeyName = $Value;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
Set-Content -Path $CacheFile -Value (ConvertTo-Json -InputObject $cacheData -Depth 100) | Out-Null;
|
||
|
|
}
|