Extract query into separate file
Extract cache handling to a separate file