added StackOverflow's solution for image caching. To be refactored