Refactoring/cache factory

Move cache factory logic out to separate class