Add caching to `toArray` method

Reflection can be slow on occasions and this optimization should be beneficial if `toArray` is being called more than once per request.