Add first tests to query. Refactoring starts.
Extract cache component from query

The cache component is a sub-namespace of the query namespace.
This helps to get a better separation of code and a much clearer
interface of query.
This commit only extracts the cache from schema to the hierarchy.
The cache functions are not replaced in query yet.
Port the levels layer in query.cache.