refactor cookies and cacheFactory management