Implemented caching.

The #queries are droped down heavily.