Set-PSUCache Does Not Accept Null

Product: PowerShell Universal
Version: 3.7.14

Running “Set-PSUCache -Key ‘MyKeyName’ -Value $null” presents the error “Cannot bind argument to parameter ‘Value’ because it is null.” In some cases, I do want to set keys to null, and if we consider the PSU cache to be a kind of storage point to hold variables or other data that needs to cross between runspaces then $null is a legitimate datatype.

I’d love to see Set-PSUCache updated to have the Value parameter updated with [AllowEmptyCollection()], [AllowEmptyString()], and/or [AllowNull()]. Or even a -Null switch to allow clearing a cache variable that was previous set with Set-PSUCache.

Hi @sean-sauve,

Could you use the -AbsoluteExpirationFromNow parameter to clear it in a seconds time?

Yeah, that would work. Not ideal because then I’ll have to make a wrapper function or a try block around both the Set-PSUCache to test for null, and Get-PSUCache or it will error the next time it’s called, and the particular key that I’m setting doesn’t normally have an expiration. Thanks for the suggestion.