Skip to content

Commit 5d6a28c

Browse files
Merge pull request #727 from PowershellFrameworkCollective/caching
1.14.438
2 parents 79ee6cd + 7454907 commit 5d6a28c

28 files changed

Lines changed: 1947 additions & 20 deletions

PSFramework/PSFramework.psd1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
RootModule = 'PSFramework.psm1'
55

66
# Version number of this module.
7-
ModuleVersion = '1.13.426'
7+
ModuleVersion = '1.14.438'
88

99
# ID used to uniquely identify this module
1010
GUID = '8028b914-132b-431f-baa9-94a6952f21ff'
@@ -98,6 +98,7 @@
9898
'Invoke-PSFFilter'
9999
'Invoke-PSFRunspace'
100100
'Join-PSFPath'
101+
'New-PSFCache'
101102
'New-PSFFilter'
102103
'New-PSFFilterCondition'
103104
'New-PSFFilterConditionSet'

PSFramework/bin/PSFramework.dll

12.5 KB
Binary file not shown.

PSFramework/bin/PSFramework.pdb

40 KB
Binary file not shown.

PSFramework/bin/PSFramework.xml

Lines changed: 512 additions & 1 deletion
Large diffs are not rendered by default.

PSFramework/bin/assembly.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ catch {
1111
throw
1212
}
1313
try {
14+
$lock = [PSFramework.Runspace.RunspaceHost]::GetRunspaceLock('PSFramework.Types')
15+
$lock.Open()
1416
Update-TypeData -AppendPath "$script:ModuleRoot\xml\PSFramework.Types.ps1xml" -ErrorAction Stop
17+
$lock.Close()
1518
}
1619
catch {
1720
Write-Warning "Failed to load PSFramework type extensions! Unable to import module."

PSFramework/changelog.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# CHANGELOG
22

3+
## 1.14.438 (2026-05-31)
4+
5+
- New: New-PSFCache - creates a configurable in-memory cache.
6+
- New: Config validation urihttp - Validates http uris (#719)
7+
- Ipd: Disable-PSFLoggingProvider - now accepts input from pipeline from Get-PSFLoggingProviderInstance
8+
- Upd: PSFDateTime - Now tracking what time the object was created at (`InstantiationTime`)
9+
- Upd: PSFDateTime - Now tracking the resolved relative time provided (`Delta`)
10+
- Upd: PSFDateTime - new method `Reverse()` to reverse relative time between positive and negative.
11+
- Upd: PSFDateTime - new method `Past()` to make sure relative-provided time points to the past
12+
- Upd: PSFDateTime - new method `Future()` to make sure relative-provided time points to the future
13+
- Fix: Write-PSFHostColor - Fails when trying to colorize special regex characters (#721)
14+
- Fix: Error loading PSFramework concurrently
15+
- Fix: Config Validation uriabsolute - accepts hostless stump (#719)
16+
- Fix: Disable-PSFConsoleInterrupt - fails in contexts that do not have a console window handle such as remoting. (#724, @Mr-Kappelmann)
17+
318
## 1.13.426 (2026-01-13)
419

520
- Fix: Write-PSFHostColor - Ignores the `-NoNewLine` parameter
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
function New-PSFCache {
2+
<#
3+
.SYNOPSIS
4+
Create a new Cache object.
5+
6+
.DESCRIPTION
7+
Create a new Cache object.
8+
9+
.PARAMETER MaxItems
10+
The maximum number of items allowed in the cache.
11+
12+
.PARAMETER Lifetime
13+
The maximum age for values in the cache.
14+
15+
.PARAMETER TryDispose
16+
When expiring values from the cache, should we try to explicitly dispose them?
17+
18+
.PARAMETER Collector
19+
When asking for a value that hasn't been cached yet, retrieve the value using this logic.
20+
Note: If this script fails, the retrieval errors.
21+
22+
.PARAMETER CollectNull
23+
When executing the collector scriptblock, should we consider an empty / null return valid and cache it?
24+
This prevents repeated requests to the same key triggering the Collector script, which may save time.
25+
It also prevents it from noticing if something changed.
26+
27+
.EXAMPLE
28+
PS C:\> New-PSFCache -MaxItems 50000
29+
30+
Creates a cache that will retain the last 50000 items.
31+
32+
.EXAMPLE
33+
PS C:\> New-PSFCache -Lifetime 30m
34+
35+
Creates a cache that will retain values for 30 minutes.
36+
37+
.EXAMPLE
38+
PS C:\> New-PSFCache -MaxItems 50000 -Collector { Get-ADGroup -Identity $_ }
39+
40+
Creates a cache that will retain the last 50000 items, looking up Active Directory groups when asked for an entry it doesn't know yet.
41+
#>
42+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
43+
[OutputType([PSFramework.Caching.CacheMemoryConcurrent])]
44+
[CmdletBinding()]
45+
param (
46+
[long]
47+
$MaxItems,
48+
49+
[PsfTimeSpan]
50+
$Lifetime,
51+
52+
[switch]
53+
$TryDispose,
54+
55+
[PsfScriptBlock]
56+
$Collector,
57+
58+
[switch]
59+
$CollectNull
60+
)
61+
process {
62+
$cache = [PSFramework.Caching.CacheMemoryConcurrent]::new()
63+
64+
if ($MaxItems) { $cache.SetMaxItems($MaxItems) }
65+
if ($Lifetime) { $cache.SetLifetime($Lifetime) }
66+
if ($TryDispose) { $cache.SetTryDispose($TryDispose) }
67+
if ($Collector) { $cache.SetCollector($Collector) }
68+
if ($CollectNull) { $cache.SetCacheNull($CollectNull) }
69+
70+
$cache
71+
}
72+
}

PSFramework/functions/logging/Disable-PSFLoggingProvider.ps1

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
.PARAMETER InstanceName
1717
Name of the instance of the logging provider to disable.
1818
Defaults to: Default
19+
20+
.PARAMETER InstanceObject
21+
A full Logging Provider Instance object, as return by Get-PSFLoggingProviderInstance
1922
2023
.PARAMETER NoFinalizeWait
2124
Do not wait for the logging to conclude or the final events shutting down the provider instance to finish.
@@ -43,34 +46,59 @@
4346
4447
Disables the "mytask" instance of the logfile provider, then waits until all applicable logs are processed
4548
but not for the logfile to be released (which will happen soon after, in most cases).
49+
50+
.EXAMPLE
51+
PS C:\> Get-PSFLoggingProviderInstance | Disable-PSFLoggingProvider
52+
53+
Disables all active logging provider instacnes
4654
#>
47-
[CmdletBinding()]
55+
[CmdletBinding(DefaultParameterSetName = 'ByName')]
4856
param (
49-
[Parameter(Mandatory = $true)]
57+
[Parameter(Mandatory = $true, ParameterSetName = 'ByName')]
5058
[PsfArgumentCompleter('PSFramework-logging-provider')]
5159
[ValidateNotNullOrEmpty()]
5260
[Alias('Provider', 'ProviderName')]
5361
[string]
5462
$Name,
5563

64+
[Parameter(ParameterSetName = 'ByName')]
5665
[PsfArgumentCompleter('PSFramework-logging-instance-name2')]
5766
[string]
5867
$InstanceName = 'Default',
5968

69+
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'ByObject')]
70+
[PSFramework.Logging.ProviderInstance[]]
71+
$InstanceObject,
72+
6073
[switch]
6174
$NoFinalizeWait
6275
)
6376

64-
process {
77+
begin {
78+
$inInstances = [System.Collections.ArrayList]@()
6579
$limit = Get-Date
66-
$instances = Get-PSFLoggingProviderInstance -ProviderName $Name -Name $InstanceName
67-
68-
foreach ($instance in $instances) {
69-
$instance.NotAfter = $limit
80+
}
81+
process {
82+
if ($Name) {
83+
$instances = Get-PSFLoggingProviderInstance -ProviderName $Name -Name $InstanceName
84+
85+
foreach ($instance in $instances) {
86+
$instance.NotAfter = $limit
87+
}
88+
89+
foreach ($instance in $instances) {
90+
$instance.Drain((-not $NoFinalizeWait))
91+
}
7092
}
7193

72-
foreach ($instance in $instances) {
73-
$instance.Drain((-not $NoFinalizeWait))
94+
foreach ($instance in $InstanceObject) {
95+
$instance.NotAfter = $limit
96+
$null = $inInstances.Add($instance)
7497
}
7598
}
99+
end {
100+
foreach ($instance in $inInstances) {
101+
$instance.Drain((-not $NoFinalizeWait))
102+
}
103+
}
76104
}

PSFramework/functions/message/Write-PSFHostColor.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
$match = ($row | Select-String '<c=["''](.*?)["'']>(.*?)</c>' -AllMatches).Matches
127127
if ($useAnsi) {
128128
foreach ($entry in $match) {
129-
$row = $row -replace $entry.Groups[0].Value, "$($escape)$($colorMap[$entry.Groups[1].Value])m$($entry.Groups[2].Value)$($escape)$($defaultCode)m"
129+
$row = $row -replace ([regex]::Escape($entry.Groups[0].Value)), "$($escape)$($colorMap[$entry.Groups[1].Value])m$($entry.Groups[2].Value)$($escape)$($defaultCode)m"
130130
}
131131
Microsoft.PowerShell.Utility\Write-Host -Object $row -ForegroundColor $DefaultColor -NoNewline:$NoNewLine
132132
continue

PSFramework/functions/runspace/Set-PSFDynamicContentObject.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272

7373
[Parameter(Mandatory = $true, ParameterSetName = 'Value')]
7474
[AllowNull()]
75-
$Value = $null,
75+
$Value,
7676

7777
[Parameter(Mandatory = $true, ParameterSetName = 'Queue')]
7878
[switch]

0 commit comments

Comments
 (0)