[4303] Caching. Improved cache function and tests.