Problems caching custom classes caused by serialization

Product: PowerShell Universal
Version: 3.2.5

I’ve got a custom module ARAH which provides a custom class [ARAHConnection], which is used for generic REST API Access.

If I store an instance of an ARAHConnection object with Set-PSUCache the retrieved object is of type [Deserialized.ARAHConnection] and cannot be used as a parameter which is of the original type.

This behavior can be also observed using Export-CliXml, see StackOverflow.

Does somebody have an idea for a workaround instead of creating manual shadow copy functionality?

You could try to convert it to JSON and then store it in the cache. When reading it from the cache, you could then convert it back to the specific type.