Thread-safe caching solution