implemented a helper function for caching