Product: PowerShell Universal Version: 5.4.4
Set-PSUCache allows for multiple values with the same key, is this intended?
1. Violates the core principle of key-value stores
2. Unpredictable behavior
Get-Cache?3. Data inconsistency and logic errors
4. Makes the cache harder to manage and debug
5. Performance and memory overhead
6. Undermines concurrency safety
7. Misleads developers
Set-Cache -Key "MyKey" -Value "abc" to replace the previous value. If instead it silently adds another value for the same key, that’s counter-intuitive and leads to incorrect assumptions in code.Get-PSUCache shouldn’t be allowing multiple values per key. I just did this test and it behaves as I would expect.
Set-PSUCache -Key '123' -Value '123'
Set-PSUCache -Key '123' -Value '456'
Set-PSUCache -Key '123' -Value '789'
Get-PSUCache -Key '123'
Set-PSUCache -Key 'xyz' -Value '123' -Persist
Set-PSUCache -Key 'xyz' -Value '456' -Persist
Set-PSUCache -Key 'xyz' -Value '789' -Persist
Get-PSUCache -Key 'xyz'
Get-PSUCache -List
# Output
789
789
Key : xyz
Value : <Objs Version="1.1.0.1" xmlns="http://schemas
.microsoft.com/powershell/2004/04">
<S>789</S>
</Objs>
AbsoluteExpiration :
AbsoluteExpirationRelativeToNow :
SlidingExpiration :
Persist : True
Roles :
SecurityContextId : 00000000-0000-0000-0000-000000000000
LastRead : 4/4/2025 1:41:49 PM
Created : 4/4/2025 1:41:23 PM
Updated : 4/4/2025 1:41:49 PM
Id : 0
Key : 123
Value : <Objs Version="1.1.0.1" xmlns="http://schemas
.microsoft.com/powershell/2004/04">
<S>789</S>
</Objs>
AbsoluteExpiration :
AbsoluteExpirationRelativeToNow :
SlidingExpiration :
Persist : False
Roles :
SecurityContextId : 00000000-0000-0000-0000-000000000000
LastRead : 4/4/2025 1:41:49 PM
Created : 4/4/2025 1:40:57 PM
Updated : 4/4/2025 1:41:49 PM
Id : 0Adam Driscoll
PowerShell Expert and Developer at Devolutions
Is this chatgpt?
Did you avoid setting same Key with -persist on and off on purpose :D? Because this is exactly the problem. And when I want to remove one it always defaults to the oldest one
Set-PSUCache -Key 'Example' -value '123'
Set-PSUCache -Key 'Example' -value '123' -Persist
Get-PSUCache -key 'Example'
123
Get-PSUCache -List
Key : Example
Value : <Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04">
<S>123</S>
</Objs>
AbsoluteExpiration :
AbsoluteExpirationRelativeToNow :
SlidingExpiration :
Persist : True
Roles :
SecurityContextId : 00000000-0000-0000-0000-000000000000
LastRead : 2025-04-07 07:09:33
Created : 2025-04-07 07:09:12
Updated : 2025-04-07 07:09:12
Id : 0
Key : Example
Value : <Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04">
<S>123</S>
</Objs>
AbsoluteExpiration :
AbsoluteExpirationRelativeToNow :
SlidingExpiration :
Persist : False
Roles :
SecurityContextId : 00000000-0000-0000-0000-000000000000
LastRead : 2025-04-07 07:09:47
Created : 2025-04-07 07:09:02
Updated : 2025-04-07 07:09:02
Id : 0Dont know how this is relevant but it helps me write in English since its my 2nd language
I understand the issue now. The problem is that we don’t clear the non-persistent item when settings the same key for a persistent item.
Adam Driscoll
PowerShell Expert and Developer at Devolutions
Great thanks