Move cache handling into its own file