Implemented caching of viewport dimensions.

Resolves issue #51.