1. version of cache function