Properly serialize RecentlyUsedContainers for cache

RecentlyUsedContainers are threadsafe so they require a lock and as such
cannot be serialized with pickle directly. To handle it, we need to
convert it to a dictionary first and then back when deserializing.

Fixes #2345
Merge pull request #2349 from sigmavirus24/fix-pickling

Properly serialize RecentlyUsedContainers for cache