Move cache code to own module