cacheservice unit tests and refactoring to handle errors better