`Set-PSUCache -SlidingExpiration` does not actually expire after the specified timespan

I’m trying to use Set-PSUCache ... -SlidingExpiration [TimeSpan]::FromMinutes(10) within one API endpoint, and accessing it with Get-PSUCache from within another API endpoint. However even after waiting 30 minutes, the cached data remains available.

Is this a bug, or am I using it incorrectly?

Product: PowerShell Universal
Version: 2.4.1

I can reproduce this. It’s a bug and I’ll open an issue for it.

1 Like

Btw, the documentation for Get-PSUCache does not mention this; but what is the expected behaviour when specifying a value for -Name that does not exist (anymore)?

Will it return $Null, or produce a stopping error?

The latter would allow me to use a Try {...} Catch {...} approach, which is preferable to something like If ([boolean](Get-PSUCache -Name 'Foo')) {...} Else {...}

It returns null and will not throw an error.

We likely wouldn’t change that behavior until 3.0 but we could introduce either a switch on Get-PSUCache to cause it to throw or introduce something like Test-PSUCache to check if a key exists.

Good to know! Thanks for the quick response. I’m liking PSU a lot so far :slight_smile:

Awesome! Glad to hear it.