refactor caching to separate files