Refactoring code for caching  product